Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,25 @@ import gradio as gr
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
-
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def respond(
|
9 |
message,
|
10 |
history: list[tuple[str, str]],
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
top_p,
|
15 |
):
|
16 |
-
messages = [{"role": "system", "content":
|
17 |
|
18 |
for val in history:
|
19 |
if val and len(val) == 2:
|
@@ -40,24 +47,8 @@ def respond(
|
|
40 |
response += token
|
41 |
yield response
|
42 |
|
43 |
-
|
44 |
-
default_system_prompt = (
|
45 |
-
"You are a professional pharmacist who ONLY answers questions related to medications, including uses, dosages, side effects, interactions, and recommendations. "
|
46 |
-
"If the user asks about anything NOT related to medications, politely reply that you can only help with medication-related questions and suggest they consult other resources. "
|
47 |
-
"Always ask for the user's age before giving any dosage or advice. "
|
48 |
-
"Include a clear disclaimer at the end: "
|
49 |
-
"\"This information is for educational purposes only and does not replace professional medical advice. Please consult a licensed healthcare provider.\""
|
50 |
-
)
|
51 |
-
|
52 |
-
demo = gr.ChatInterface(
|
53 |
-
respond,
|
54 |
-
additional_inputs=[
|
55 |
-
gr.Textbox(value=default_system_prompt, label="System message", lines=5),
|
56 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
57 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.2, step=0.1, label="Temperature"),
|
58 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
59 |
-
],
|
60 |
-
)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
+
#client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
+
client = InferenceClient("stanford-crfm/BioMedLM")
|
7 |
+
|
8 |
+
default_system_prompt = (
|
9 |
+
"You are a professional pharmacist who ONLY answers questions related to medications, including uses, dosages, side effects, interactions, and recommendations. "
|
10 |
+
"If the user asks about anything NOT related to medications, politely reply that you can only help with medication-related questions and suggest they consult other resources. "
|
11 |
+
"Always ask for the user's age before giving any dosage or advice. "
|
12 |
+
"Include a clear disclaimer at the end: "
|
13 |
+
"\"This information is for educational purposes only and does not replace professional medical advice. Please consult a licensed healthcare provider.\""
|
14 |
+
)
|
15 |
|
16 |
def respond(
|
17 |
message,
|
18 |
history: list[tuple[str, str]],
|
19 |
+
max_tokens=512,
|
20 |
+
temperature=0.2,
|
21 |
+
top_p=0.95,
|
|
|
22 |
):
|
23 |
+
messages = [{"role": "system", "content": default_system_prompt}]
|
24 |
|
25 |
for val in history:
|
26 |
if val and len(val) == 2:
|
|
|
47 |
response += token
|
48 |
yield response
|
49 |
|
50 |
+
demo = gr.ChatInterface(respond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
demo.launch(share=True)
|
54 |
+
|