Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,84 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from gtts import gTTS
|
4 |
-
from youtubesearchpython import VideosSearch
|
5 |
import os
|
|
|
6 |
|
7 |
-
# Initialize the
|
8 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
9 |
|
10 |
-
# Streamlit app
|
11 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
# Respond to user input
|
17 |
if user_input:
|
18 |
-
# Generate a response from the
|
19 |
-
response = chatbot(user_input, max_length=
|
20 |
-
st.text_area("Bot:", response, height=
|
21 |
-
|
22 |
-
#
|
23 |
-
tts = gTTS(
|
24 |
-
|
25 |
-
audio_file
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
st.
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
st.write(
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from gtts import gTTS
|
|
|
4 |
import os
|
5 |
+
from youtubesearchpython import VideosSearch
|
6 |
|
7 |
+
# Initialize the conversational model
|
8 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
9 |
|
10 |
+
# Streamlit app layout with positive, calming design
|
11 |
+
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="ποΈ", layout="centered")
|
12 |
+
|
13 |
+
# Customizing the app style for a soothing and modern look
|
14 |
+
st.markdown("""
|
15 |
+
<style>
|
16 |
+
.css-1d391kg {
|
17 |
+
background-color: #F3F7F6;
|
18 |
+
}
|
19 |
+
.css-ffhzg2 {
|
20 |
+
font-size: 1.5em;
|
21 |
+
font-weight: 500;
|
22 |
+
color: #4C6D7D;
|
23 |
+
}
|
24 |
+
.stTextInput>div>div>input {
|
25 |
+
background-color: #D8E3E2;
|
26 |
+
}
|
27 |
+
.stButton>button {
|
28 |
+
background-color: #A9D0B6;
|
29 |
+
color: white;
|
30 |
+
border-radius: 5px;
|
31 |
+
border: none;
|
32 |
+
}
|
33 |
+
.stButton>button:hover {
|
34 |
+
background-color: #8FB79A;
|
35 |
+
}
|
36 |
+
.stTextInput>div>label {
|
37 |
+
color: #4C6D7D;
|
38 |
+
}
|
39 |
+
</style>
|
40 |
+
""", unsafe_allow_html=True)
|
41 |
|
42 |
+
# Title and introduction
|
43 |
+
st.title("Grief and Loss Support Bot ποΈ")
|
44 |
+
st.subheader("We are here for you. π Your companion in tough times")
|
45 |
+
|
46 |
+
# User input for conversation
|
47 |
+
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
48 |
|
|
|
49 |
if user_input:
|
50 |
+
# Generate a compassionate response from the bot
|
51 |
+
response = chatbot(user_input, max_length=150)[0]['generated_text']
|
52 |
+
st.text_area("Bot's Response:", response, height=150)
|
53 |
+
|
54 |
+
# Empathetic voice output using gTTS
|
55 |
+
tts = gTTS(response, lang='en')
|
56 |
+
audio_file = "response.mp3"
|
57 |
+
tts.save(audio_file)
|
58 |
+
st.audio(audio_file, format="audio/mp3", use_container_width=True)
|
59 |
+
|
60 |
+
# Crisis keyword detection for emergency help
|
61 |
+
crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
|
62 |
+
if any(keyword in user_input.lower() for keyword in crisis_keywords):
|
63 |
+
st.warning("It seems like you might be in distress. Please reach out to a crisis hotline or a trusted individual for support. You're not alone.")
|
64 |
+
st.write("[Find emergency resources here](https://www.helpguide.org/find-help.htm)")
|
65 |
+
|
66 |
+
# Productive hobby suggestions
|
67 |
+
if st.button("Need something to do? Here are some activities to help you cope:"):
|
68 |
+
st.write("- Journaling your thoughts and emotions π")
|
69 |
+
st.write("- Painting or drawing your feelings π¨")
|
70 |
+
st.write("- Taking a walk in nature π³")
|
71 |
+
st.write("- Listening to soothing music πΆ")
|
72 |
+
st.write("- Practicing deep breathing or meditation π§")
|
73 |
+
st.write("- Trying out a new hobby like knitting or gardening π±")
|
74 |
+
|
75 |
+
# YouTube content suggestions for coping with grief
|
76 |
+
if st.button("Here are some videos that may help you:"):
|
77 |
+
videos_search = VideosSearch('coping with grief', limit=3)
|
78 |
+
results = videos_search.result()['result']
|
79 |
+
for i, video in enumerate(results):
|
80 |
+
st.write(f"{i + 1}. [{video['title']}]({video['link']})")
|
81 |
+
|
82 |
+
# Clean up the audio file after playback
|
83 |
+
if os.path.exists(audio_file):
|
84 |
+
os.remove(audio_file)
|