Spaces:
Runtime error
Runtime error
Delete calmmate.py
Browse files- calmmate.py +0 -60
calmmate.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|