Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,12 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
from gtts import gTTS
|
4 |
from pytube import Search
|
5 |
-
import random
|
6 |
import os
|
7 |
|
8 |
# Initialize conversational models
|
9 |
conversational_bot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
10 |
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
11 |
-
|
12 |
-
# Motivational quotes list
|
13 |
-
motivational_quotes = [
|
14 |
-
"You are stronger than you think. Keep going, one step at a time.",
|
15 |
-
"It's okay to take a break. Your mental health matters too.",
|
16 |
-
"This moment is tough, but it will pass. Stay strong.",
|
17 |
-
"Believe in yourself. You've faced challenges before and overcome them.",
|
18 |
-
"Don't give up. Progress is progress, no matter how small."
|
19 |
-
]
|
20 |
|
21 |
# Set up Streamlit page
|
22 |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="🌿", layout="centered")
|
@@ -42,40 +33,32 @@ user_input = st.text_input("Share what's on your mind...", placeholder="Type her
|
|
42 |
if user_input:
|
43 |
# Run sentiment analysis for crisis detection
|
44 |
sentiment = sentiment_analysis(user_input)[0]
|
45 |
-
|
46 |
# Use conversational bot for responses
|
47 |
response = conversational_bot(user_input, max_length=150)[0]['generated_text']
|
48 |
-
|
49 |
# Display response
|
50 |
st.text_area("Bot's Response:", response, height=150)
|
51 |
|
52 |
-
#
|
53 |
-
|
54 |
-
st.
|
55 |
|
56 |
-
# Text-to-speech output
|
57 |
-
tts = gTTS(
|
58 |
audio_file = "response.mp3"
|
59 |
tts.save(audio_file)
|
60 |
st.audio(audio_file, format="audio/mp3") # Removed use_container_width=True
|
61 |
|
62 |
# Suggest a productive activity based on detected keywords
|
63 |
-
if any(keyword in user_input.lower() for keyword in ["lonely", "lost", "sad"
|
64 |
-
st.info("Here's a suggestion to help
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"exercise": ["light yoga", "stretching", "taking a walk outside"],
|
69 |
-
"self-care": ["taking a warm bath", "getting a good night's sleep", "reading a book"]
|
70 |
-
}
|
71 |
-
category = st.selectbox("Choose an activity category:", ["relaxation", "creative", "exercise", "self-care"])
|
72 |
-
activity = random.choice(activities[category])
|
73 |
-
|
74 |
-
st.write(f"Activity Suggestion: {activity}")
|
75 |
-
|
76 |
# Search YouTube for videos related to the selected activity
|
77 |
search = Search(activity)
|
78 |
-
search_results = search.results[:
|
79 |
for video in search_results:
|
80 |
st.write(f"[{video.title}]({video.watch_url})")
|
81 |
|
|
|
2 |
from transformers import pipeline
|
3 |
from gtts import gTTS
|
4 |
from pytube import Search
|
|
|
5 |
import os
|
6 |
|
7 |
# Initialize conversational models
|
8 |
conversational_bot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
9 |
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
10 |
+
motivational_response = pipeline("text-generation", model="huggingtweets/motivational")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Set up Streamlit page
|
13 |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="🌿", layout="centered")
|
|
|
33 |
if user_input:
|
34 |
# Run sentiment analysis for crisis detection
|
35 |
sentiment = sentiment_analysis(user_input)[0]
|
36 |
+
|
37 |
# Use conversational bot for responses
|
38 |
response = conversational_bot(user_input, max_length=150)[0]['generated_text']
|
39 |
+
|
40 |
# Display response
|
41 |
st.text_area("Bot's Response:", response, height=150)
|
42 |
|
43 |
+
# Generate motivational message
|
44 |
+
motivation = motivational_response(user_input, max_length=150)[0]['generated_text']
|
45 |
+
st.text_area("Motivational Response:", motivation, height=150)
|
46 |
|
47 |
+
# Text-to-speech output for both responses
|
48 |
+
tts = gTTS(response + " " + motivation, lang='en')
|
49 |
audio_file = "response.mp3"
|
50 |
tts.save(audio_file)
|
51 |
st.audio(audio_file, format="audio/mp3") # Removed use_container_width=True
|
52 |
|
53 |
# Suggest a productive activity based on detected keywords
|
54 |
+
if any(keyword in user_input.lower() for keyword in ["lonely", "lost", "sad"]):
|
55 |
+
st.info("Here's a suggestion to help you cope:")
|
56 |
+
hobbies = ["journaling", "yoga", "painting"]
|
57 |
+
activity = st.selectbox("Choose an activity you'd like to try:", hobbies)
|
58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Search YouTube for videos related to the selected activity
|
60 |
search = Search(activity)
|
61 |
+
search_results = search.results[:3] # limit results to 2 videos
|
62 |
for video in search_results:
|
63 |
st.write(f"[{video.title}]({video.watch_url})")
|
64 |
|