Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
from gtts import gTTS
|
4 |
from pytube import Search
|
5 |
import random
|
6 |
import os
|
7 |
|
8 |
-
# Initialize
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Configure Streamlit page
|
13 |
st.set_page_config(page_title="Grief & Loss Support Bot", page_icon="🌱", layout="centered")
|
@@ -28,29 +30,31 @@ st.subheader("Your compassionate companion in tough times 💚")
|
|
28 |
# User input
|
29 |
user_input = st.text_input("How are you feeling today?", placeholder="Share your thoughts here...", max_chars=500)
|
30 |
|
31 |
-
#
|
32 |
if user_input:
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
# Display empathetic response
|
37 |
-
st.text_area("Bot's Response:",
|
38 |
-
|
39 |
# Convert text to speech for added comfort
|
40 |
-
tts = gTTS(
|
41 |
audio_file = "response.mp3"
|
42 |
tts.save(audio_file)
|
43 |
st.audio(audio_file, format="audio/mp3")
|
44 |
|
45 |
-
#
|
46 |
-
mood = sentiment['label'].lower()
|
47 |
activity_suggestions = {
|
48 |
"positive": ["try journaling your feelings", "practice yoga", "learn a new recipe"],
|
49 |
"neutral": ["take a short walk", "listen to calming music", "try some mindful breathing"],
|
50 |
"negative": ["explore creative activities like painting", "watch a motivational video", "write down small goals to feel organized"]
|
51 |
}
|
52 |
-
activities = activity_suggestions
|
53 |
-
|
54 |
# Show dynamic activity suggestion
|
55 |
st.info("Here’s something you could try to lift your spirits:")
|
56 |
selected_activity = random.choice(activities)
|
@@ -61,7 +65,7 @@ if user_input:
|
|
61 |
st.write("Recommended Videos:")
|
62 |
for video in search.results[:2]: # Display top 2 videos
|
63 |
st.write(f"[{video.title}]({video.watch_url})")
|
64 |
-
|
65 |
# Crisis response if critical keywords are detected
|
66 |
crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
|
67 |
if any(keyword in user_input.lower() for keyword in crisis_keywords):
|
|
|
1 |
import streamlit as st
|
2 |
+
from llama_cpp import Llama
|
3 |
from gtts import gTTS
|
4 |
from pytube import Search
|
5 |
import random
|
6 |
import os
|
7 |
|
8 |
+
# Initialize the Llama model
|
9 |
+
llm = Llama.from_pretrained(
|
10 |
+
repo_id="featherless-ai-quants/HyunCello-KULLM3-empathy-v1.0-GGUF",
|
11 |
+
filename="HyunCello-KULLM3-empathy-v1.0-IQ4_XS.gguf"
|
12 |
+
)
|
13 |
|
14 |
# Configure Streamlit page
|
15 |
st.set_page_config(page_title="Grief & Loss Support Bot", page_icon="🌱", layout="centered")
|
|
|
30 |
# User input
|
31 |
user_input = st.text_input("How are you feeling today?", placeholder="Share your thoughts here...", max_chars=500)
|
32 |
|
33 |
+
# Generate empathetic response using Llama model
|
34 |
if user_input:
|
35 |
+
response = llm.create_chat_completion(
|
36 |
+
messages=[
|
37 |
+
{"role": "user", "content": user_input}
|
38 |
+
]
|
39 |
+
)['choices'][0]['message']['content']
|
40 |
|
41 |
# Display empathetic response
|
42 |
+
st.text_area("Bot's Response:", response, height=150)
|
43 |
+
|
44 |
# Convert text to speech for added comfort
|
45 |
+
tts = gTTS(response, lang='en')
|
46 |
audio_file = "response.mp3"
|
47 |
tts.save(audio_file)
|
48 |
st.audio(audio_file, format="audio/mp3")
|
49 |
|
50 |
+
# Suggested activities based on user input
|
|
|
51 |
activity_suggestions = {
|
52 |
"positive": ["try journaling your feelings", "practice yoga", "learn a new recipe"],
|
53 |
"neutral": ["take a short walk", "listen to calming music", "try some mindful breathing"],
|
54 |
"negative": ["explore creative activities like painting", "watch a motivational video", "write down small goals to feel organized"]
|
55 |
}
|
56 |
+
activities = activity_suggestions["neutral"] # Default to "neutral" for simplicity
|
57 |
+
|
58 |
# Show dynamic activity suggestion
|
59 |
st.info("Here’s something you could try to lift your spirits:")
|
60 |
selected_activity = random.choice(activities)
|
|
|
65 |
st.write("Recommended Videos:")
|
66 |
for video in search.results[:2]: # Display top 2 videos
|
67 |
st.write(f"[{video.title}]({video.watch_url})")
|
68 |
+
|
69 |
# Crisis response if critical keywords are detected
|
70 |
crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
|
71 |
if any(keyword in user_input.lower() for keyword in crisis_keywords):
|