File size: 1,873 Bytes
7a65471
9a62e92
732a7be
3be14f8
 
 
9a62e92
 
7a65471
3be14f8
3d848d4
3be14f8
 
 
 
 
7a65471
3be14f8
9a62e92
3be14f8
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

# โหลดโมเดล Falcon-RW-1B
model_id = "tiiuae/falcon-rw-1b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)

# ฟังก์ชันตอบกลับ
def ask_doctor(message, history):
    prompt = f"You are a friendly, professional doctor who gives clear, concise advice.\n\nPatient: {message}\nDoctor:"
    response = generator(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)[0]["generated_text"]
    answer = response.split("Doctor:")[-1].strip()
    answer += "\n\n⚠️ คำตอบนี้เพื่อการศึกษา ไม่แทนการวินิจฉัยจากแพทย์จริง"
    return answer

# สร้างหน้าตาแชตแบบ Chatbot
with gr.Blocks() as demo:
    gr.Markdown("""
        # 🩺 ปรึกษาหมอ AI
        ### หมอ AI พร้อมให้คำแนะนำเบื้องต้นด้านสุขภาพแบบรวดเร็ว ใช้โมเดล Falcon-RW-1B ฟรีจาก Hugging Face
        > ❗ **ข้อมูลนี้ใช้เพื่อการศึกษาเท่านั้น ไม่แทนการวินิจฉัยทางการแพทย์จริง**
    """)
    chatbot = gr.ChatInterface(
        fn=ask_doctor,
        title="แชตกับหมอ AI 🤖",
        chatbot=gr.Chatbot(height=400),
        textbox=gr.Textbox(placeholder="พิมพ์คำถาม เช่น 'ปวดหัวมาก ต้องทำยังไงดี?'", scale=7),
        theme="default"
    )

demo.launch()