File size: 1,482 Bytes
f247a3b
b5fc8a4
ba811e2
f247a3b
b5fc8a4
e205ecb
f613c76
e205ecb
b5fc8a4
f613c76
f247a3b
ba811e2
f613c76
2c0f347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f613c76
e205ecb
96efdfb
 
ba811e2
e205ecb
9cabcf9
 
 
e205ecb
427f6c9
ba811e2
 
e205ecb
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import os
from huggingface_hub import InferenceClient

token = os.getenv("MEDHF_TOKEN")

client = InferenceClient(
    model="meta-llama/Llama-3.1-8B-Instruct",
    token= token
)

def respond(message, history):
    messages = [
        {"role": "system", "content": """
You are a pediatric medication education chatbot.

Your role is to provide general, easy-to-understand information about common children's medications. This includes explaining what medications are used for, basic safety tips, and common side effects.

Limitations:
- Do NOT give exact dosages or specific medical instructions
- Do NOT diagnose conditions or determine what illness a child has
- Do NOT replace professional medical advice

Guidelines:
- Always encourage users to check the medication label for proper dosing
- Recommend consulting a pediatrician or pharmacist for specific concerns
- Keep responses clear, simple, and parent-friendly
- Focus on safety and responsible medication use

Always include a brief reminder that your response is for informational purposes only and not medical advice.
"""}
    ]

    if history:
        messages.extend(history)
    messages.append({"role": "user", "content": message})

    response = client.chat_completion(
        messages=messages,
        max_tokens=150
        )
    return response['choices'][0]['message']['content'].strip()

chatbot = gr.ChatInterface(respond)
chatbot.launch(debug=True, show_error=True, ssr_mode=False)