Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import random
|
|
| 4 |
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
|
|
|
| 7 |
quotes = [
|
| 8 |
"When anger rises, think of the consequences.",
|
| 9 |
"You cannot control the wind, but you can adjust your sails.",
|
|
@@ -11,51 +12,61 @@ quotes = [
|
|
| 11 |
"Peace begins with a single thought.",
|
| 12 |
"Don't let a moment of anger become a lifetime of regret."
|
| 13 |
]
|
| 14 |
-
quote_of_the_day = random.choice(quotes)
|
| 15 |
-
|
| 16 |
-
def respond(message, history):
|
| 17 |
-
system_message = "You are a calming and supportive emotional wellness chatbot named Aggro."
|
| 18 |
|
| 19 |
-
|
| 20 |
-
return {
|
| 21 |
-
"role": "assistant",
|
| 22 |
-
"content": f"Hi, I'm Aggro! π±\nQuote of the Day: \"{quote_of_the_day}\"\nHow is your day going?"
|
| 23 |
-
}
|
| 24 |
|
|
|
|
| 25 |
lowered = message.lower()
|
|
|
|
| 26 |
if "angry" in lowered:
|
| 27 |
-
|
|
|
|
| 28 |
elif "sad" in lowered:
|
| 29 |
-
|
|
|
|
| 30 |
elif "stressed" in lowered:
|
| 31 |
-
|
|
|
|
| 32 |
elif "calm" in lowered:
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
messages = [{"role": "system", "content": system_message}]
|
| 36 |
-
for
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
messages.append({"role": "user", "content": message})
|
| 39 |
|
| 40 |
response = ""
|
| 41 |
for msg in client.chat_completion(
|
| 42 |
messages,
|
| 43 |
-
max_tokens=
|
| 44 |
stream=True,
|
| 45 |
-
temperature=
|
| 46 |
-
top_p=
|
| 47 |
):
|
| 48 |
token = msg.choices[0].delta.content
|
| 49 |
response += token
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
# β
Build the interface
|
| 54 |
demo = gr.ChatInterface(
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
title="π Meet Aggro - Your Emotion Companion",
|
| 58 |
-
description=f"
|
| 59 |
)
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 4 |
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
+
# List of motivational quotes
|
| 8 |
quotes = [
|
| 9 |
"When anger rises, think of the consequences.",
|
| 10 |
"You cannot control the wind, but you can adjust your sails.",
|
|
|
|
| 12 |
"Peace begins with a single thought.",
|
| 13 |
"Don't let a moment of anger become a lifetime of regret."
|
| 14 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
quote_of_the_day = random.choice(quotes)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 19 |
lowered = message.lower()
|
| 20 |
+
|
| 21 |
if "angry" in lowered:
|
| 22 |
+
yield "I'm sorry you're feeling angry. Let's take a deep breath together. Would you like to try a calming exercise?"
|
| 23 |
+
return
|
| 24 |
elif "sad" in lowered:
|
| 25 |
+
yield "It's okay to feel sad sometimes. I'm here to support you. π"
|
| 26 |
+
return
|
| 27 |
elif "stressed" in lowered:
|
| 28 |
+
yield "Let's pause and take a deep breath. I'm here for you."
|
| 29 |
+
return
|
| 30 |
elif "calm" in lowered:
|
| 31 |
+
yield "That's great to hear! Stay present and peaceful. πΏ"
|
| 32 |
+
return
|
| 33 |
|
| 34 |
messages = [{"role": "system", "content": system_message}]
|
| 35 |
+
for user_msg, bot_msg in history:
|
| 36 |
+
if user_msg:
|
| 37 |
+
messages.append({"role": "user", "content": user_msg})
|
| 38 |
+
if bot_msg:
|
| 39 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 40 |
+
|
| 41 |
messages.append({"role": "user", "content": message})
|
| 42 |
|
| 43 |
response = ""
|
| 44 |
for msg in client.chat_completion(
|
| 45 |
messages,
|
| 46 |
+
max_tokens=max_tokens,
|
| 47 |
stream=True,
|
| 48 |
+
temperature=temperature,
|
| 49 |
+
top_p=top_p,
|
| 50 |
):
|
| 51 |
token = msg.choices[0].delta.content
|
| 52 |
response += token
|
| 53 |
+
yield response
|
| 54 |
|
| 55 |
+
# UI layout
|
|
|
|
|
|
|
| 56 |
demo = gr.ChatInterface(
|
| 57 |
+
respond,
|
| 58 |
+
additional_inputs=[
|
| 59 |
+
gr.Textbox(
|
| 60 |
+
value="You are a calming and supportive emotional wellness assistant named Aggro.",
|
| 61 |
+
label="System message",
|
| 62 |
+
visible=False
|
| 63 |
+
),
|
| 64 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 65 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 66 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 67 |
+
],
|
| 68 |
title="π Meet Aggro - Your Emotion Companion",
|
| 69 |
+
description=f"π¬ Quote of the Day: _{quote_of_the_day}_"
|
| 70 |
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|