Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,64 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
4 |
import pyttsx3
|
|
|
5 |
|
6 |
-
# Set up the
|
7 |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="ποΈ", layout="centered")
|
8 |
|
9 |
-
# Customizing the app style for a soothing
|
10 |
st.markdown("""
|
11 |
<style>
|
12 |
-
.
|
13 |
background-color: #F3F7F6;
|
14 |
}
|
15 |
-
.css-
|
16 |
-
font-
|
17 |
-
font-weight: 500;
|
18 |
-
color: #4C6D7D;
|
19 |
-
}
|
20 |
-
.stTextInput>div>div>input {
|
21 |
-
background-color: #D8E3E2;
|
22 |
-
}
|
23 |
-
.stButton>button {
|
24 |
-
background-color: #A9D0B6;
|
25 |
-
color: white;
|
26 |
-
border-radius: 5px;
|
27 |
-
border: none;
|
28 |
-
}
|
29 |
-
.stButton>button:hover {
|
30 |
-
background-color: #8FB79A;
|
31 |
-
}
|
32 |
-
.stTextInput>div>label {
|
33 |
-
color: #4C6D7D;
|
34 |
}
|
35 |
</style>
|
36 |
""", unsafe_allow_html=True)
|
37 |
|
38 |
-
# Title and introduction
|
39 |
st.title("Grief and Loss Support Bot ποΈ")
|
40 |
st.subheader("We are here for you. π Your companion in tough times")
|
41 |
|
42 |
-
#
|
43 |
-
model_name = "microsoft/DialoGPT-medium"
|
44 |
try:
|
45 |
-
|
46 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
47 |
-
text_gen_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
48 |
except Exception as e:
|
49 |
-
st.error(f"Error loading the
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
st.error(f"Error initializing the TTS engine: {e}")
|
58 |
|
59 |
# User input for conversation
|
60 |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
61 |
|
62 |
if user_input:
|
63 |
-
# Generate a
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
tts_engine.say(response_text)
|
74 |
-
tts_engine.runAndWait()
|
75 |
|
76 |
-
|
77 |
-
st.error(f"Error generating response: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
|
|
3 |
import pyttsx3
|
4 |
+
from youtubesearchpython import VideosSearch
|
5 |
|
6 |
+
# Set up the Streamlit app
|
7 |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="ποΈ", layout="centered")
|
8 |
|
9 |
+
# Customizing the app style for a soothing look
|
10 |
st.markdown("""
|
11 |
<style>
|
12 |
+
.main {
|
13 |
background-color: #F3F7F6;
|
14 |
}
|
15 |
+
.css-1d391kg {
|
16 |
+
font-family: 'Arial', sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
</style>
|
19 |
""", unsafe_allow_html=True)
|
20 |
|
|
|
21 |
st.title("Grief and Loss Support Bot ποΈ")
|
22 |
st.subheader("We are here for you. π Your companion in tough times")
|
23 |
|
24 |
+
# Set up the conversational model
|
|
|
25 |
try:
|
26 |
+
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
|
|
|
|
27 |
except Exception as e:
|
28 |
+
st.error(f"Error loading the model: {e}")
|
29 |
|
30 |
+
# Set up text-to-speech engine
|
31 |
+
engine = pyttsx3.init()
|
32 |
+
engine.setProperty('rate', 150) # Speed of speech
|
33 |
+
engine.setProperty('volume', 0.9) # Volume level
|
34 |
+
voices = engine.getProperty('voices')
|
35 |
+
engine.setProperty('voice', voices[0].id) # Choose the desired voice
|
|
|
36 |
|
37 |
# User input for conversation
|
38 |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
39 |
|
40 |
if user_input:
|
41 |
+
# Generate a response using the model
|
42 |
+
response = chatbot(user_input, max_length=100)[0]['generated_text']
|
43 |
+
|
44 |
+
# Display response and read it aloud
|
45 |
+
st.write(response)
|
46 |
+
engine.say(response)
|
47 |
+
engine.runAndWait()
|
48 |
+
|
49 |
+
# Suggest hobbies to uplift the user's mood
|
50 |
+
hobbies = ["Painting", "Reading books", "Gardening", "Learning a new language", "Playing an instrument"]
|
51 |
+
st.subheader("Suggested Hobbies")
|
52 |
+
st.write("Here are some hobbies that might help you feel better:")
|
53 |
+
for hobby in hobbies:
|
54 |
+
st.write(f"- {hobby}")
|
55 |
+
|
56 |
+
# Search for helpful YouTube videos
|
57 |
+
st.subheader("Recommended Videos")
|
58 |
+
video_search = VideosSearch('motivational activities for coping with grief', limit=3)
|
59 |
+
results = video_search.result()['result']
|
60 |
|
61 |
+
for video in results:
|
62 |
+
st.write(f"[{video['title']}]({video['link']})")
|
|
|
|
|
63 |
|
64 |
+
st.write("Remember, it's okay to seek support and take small steps towards healing. π")
|
|