Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Healthmate.py +60 -0
- app.py +67 -0
- requirements.txt +1 -0
Healthmate.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
+
|
6 |
+
def respond(
|
7 |
+
message,
|
8 |
+
history: list[tuple[str, str]],
|
9 |
+
system_message,
|
10 |
+
max_tokens,
|
11 |
+
temperature,
|
12 |
+
top_p,
|
13 |
+
):
|
14 |
+
if system_message is None:
|
15 |
+
system_message = "I'm here to help you unwind. Let's take a deep breath together."
|
16 |
+
else:
|
17 |
+
system_message = "You are a good listener. You advise relaxation exercises, suggest avoiding negative thoughts, and guide through steps to manage stress. Let's discuss what's on your mind, or ask me for a quick relaxation exercise."
|
18 |
+
|
19 |
+
messages = [{"role": "system", "content": system_message}]
|
20 |
+
|
21 |
+
for val in history:
|
22 |
+
if val[0]:
|
23 |
+
messages.append({"role": "user", "content": val[0]})
|
24 |
+
if val[1]:
|
25 |
+
messages.append({"role": "assistant", "content": val[1]})
|
26 |
+
|
27 |
+
messages.append({"role": "user", "content": message})
|
28 |
+
|
29 |
+
response = ""
|
30 |
+
|
31 |
+
for message in client.chat_completion(
|
32 |
+
messages,
|
33 |
+
max_tokens=max_tokens,
|
34 |
+
stream=True,
|
35 |
+
temperature=temperature,
|
36 |
+
top_p=top_p,
|
37 |
+
):
|
38 |
+
token = message.choices[0].delta.content
|
39 |
+
|
40 |
+
response += token
|
41 |
+
yield response
|
42 |
+
|
43 |
+
demo = gr.ChatInterface(
|
44 |
+
respond,
|
45 |
+
additional_inputs=[
|
46 |
+
gr.Textbox(value="Remember to breathe deeply. Avoid fixating on unhelpful thoughts.", label="System message"),
|
47 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
48 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
49 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
50 |
+
],
|
51 |
+
examples=[
|
52 |
+
["I feel overwhelmed with work."],
|
53 |
+
["Can you guide me through a quick meditation?"],
|
54 |
+
["How do I stop worrying about things I can't control?"]
|
55 |
+
],
|
56 |
+
title="Calm Mate"
|
57 |
+
)
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo.launch()
|
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
|
5 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
+
|
7 |
+
|
8 |
+
def respond(
|
9 |
+
message,
|
10 |
+
history: list[tuple[str, str]],
|
11 |
+
system_message,
|
12 |
+
max_tokens,
|
13 |
+
temperature,
|
14 |
+
top_p,
|
15 |
+
):
|
16 |
+
system_message = "You are a good listener. Hear the symptoms user are reporting and try to diagnose what kind of issue user might have and suggest this might be the issue and try to give some inputs to overcome this kind of issue and some good habits to avoid such issues , suggest avoiding negative thoughts, and guide through steps to manage the health issue. Discuss what's on your mind. limit the reply with 3 to 4 sentences"
|
17 |
+
messages = [{"role": "system", "content": system_message}]
|
18 |
+
|
19 |
+
for val in history:
|
20 |
+
if val[0]:
|
21 |
+
messages.append({"role": "user", "content": val[0]})
|
22 |
+
if val[1]:
|
23 |
+
messages.append({"role": "assistant", "content": val[1]})
|
24 |
+
|
25 |
+
messages.append({"role": "user", "content": message})
|
26 |
+
|
27 |
+
response = ""
|
28 |
+
|
29 |
+
for message in client.chat_completion(
|
30 |
+
messages,
|
31 |
+
max_tokens=max_tokens,
|
32 |
+
stream=True,
|
33 |
+
temperature=temperature,
|
34 |
+
top_p=top_p,
|
35 |
+
):
|
36 |
+
token = message.choices[0].delta.content
|
37 |
+
|
38 |
+
response += token
|
39 |
+
yield response
|
40 |
+
|
41 |
+
|
42 |
+
demo = gr.ChatInterface(
|
43 |
+
respond,
|
44 |
+
additional_inputs=[
|
45 |
+
gr.Textbox(value = "You are going to act like a medical practitioner, and concise and point-specific speaker. You hear the symptoms and guide tips to overcome the issue and suggest some good habits, suggest avoiding negative thoughts, and guide through steps to manage the health issue. Discuss what's on your mind, or ask me for a quick health tips.", label="System message"),
|
46 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
47 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
48 |
+
gr.Slider(
|
49 |
+
minimum=0.1,
|
50 |
+
maximum=1.0,
|
51 |
+
value=0.95,
|
52 |
+
step=0.05,
|
53 |
+
label="Top-p (nucleus sampling)",
|
54 |
+
),
|
55 |
+
],
|
56 |
+
|
57 |
+
examples = [
|
58 |
+
["I feel stressed."],
|
59 |
+
["Can you guide me through a quick health tips?"],
|
60 |
+
["How do I stop worrying about things I can't control?"]
|
61 |
+
],
|
62 |
+
title = 'Health Mate 🕊️'
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
huggingface_hub==0.22.2
|