Spaces:
Sleeping
Sleeping
File size: 720 Bytes
b8236ac f80860d b8236ac 86d9d25 f80860d 86d9d25 f80860d b8236ac 86d9d25 b8236ac 86d9d25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
model_id = "pythainlp/KhanomTanLLM-1B" # โมเดลฟรี รองรับภาษาไทย
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_id)
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
def chatbot_fn(message, history):
prompt = f"มนุษย์: {message}\nAI:"
out = generator(prompt, max_new_tokens=200, temperature=0.7)[0]["generated_text"]
answer = out.split("AI:")[-1].strip()
return answer
gr.ChatInterface(fn=chatbot_fn, title="AI ภาษาไทย (KhanomTan)").launch()
|