Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,11 @@ from gtts import gTTS
|
|
4 |
from pytube import Search
|
5 |
import os
|
6 |
|
7 |
-
# Initialize conversational
|
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")
|
@@ -31,24 +32,24 @@ user_input = st.text_input("Share what's on your mind...", placeholder="Type her
|
|
31 |
|
32 |
# Check if user has entered text
|
33 |
if user_input:
|
34 |
-
# Run sentiment analysis for
|
35 |
sentiment = sentiment_analysis(user_input)[0]
|
36 |
-
|
37 |
-
#
|
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 |
-
#
|
44 |
-
|
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")
|
52 |
|
53 |
# Suggest a productive activity based on detected keywords
|
54 |
if any(keyword in user_input.lower() for keyword in ["lonely", "lost", "sad"]):
|
@@ -58,7 +59,7 @@ if user_input:
|
|
58 |
|
59 |
# Search YouTube for videos related to the selected activity
|
60 |
search = Search(activity)
|
61 |
-
search_results = search.results[:
|
62 |
for video in search_results:
|
63 |
st.write(f"[{video.title}]({video.watch_url})")
|
64 |
|
|
|
4 |
from pytube import Search
|
5 |
import os
|
6 |
|
7 |
+
# Initialize conversational model for empathetic dialogue
|
8 |
conversational_bot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
9 |
+
|
10 |
+
# Initialize sentiment analysis
|
11 |
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
|
|
12 |
|
13 |
# Set up Streamlit page
|
14 |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="🌿", layout="centered")
|
|
|
32 |
|
33 |
# Check if user has entered text
|
34 |
if user_input:
|
35 |
+
# Run sentiment analysis to check for distress
|
36 |
sentiment = sentiment_analysis(user_input)[0]
|
37 |
+
|
38 |
+
# Generate empathetic response (model generates responses with empathy)
|
39 |
response = conversational_bot(user_input, max_length=150)[0]['generated_text']
|
40 |
+
|
41 |
+
# Ensure response does not repeat what the user said, and is supportive
|
42 |
+
if user_input.lower() in response.lower():
|
43 |
+
response = "I understand how you're feeling. You're not alone in this. I'm here to listen and help."
|
44 |
+
|
45 |
# Display response
|
46 |
st.text_area("Bot's Response:", response, height=150)
|
47 |
|
48 |
+
# Text-to-speech output
|
49 |
+
tts = gTTS(response, lang='en')
|
|
|
|
|
|
|
|
|
50 |
audio_file = "response.mp3"
|
51 |
tts.save(audio_file)
|
52 |
+
st.audio(audio_file, format="audio/mp3")
|
53 |
|
54 |
# Suggest a productive activity based on detected keywords
|
55 |
if any(keyword in user_input.lower() for keyword in ["lonely", "lost", "sad"]):
|
|
|
59 |
|
60 |
# Search YouTube for videos related to the selected activity
|
61 |
search = Search(activity)
|
62 |
+
search_results = search.results[:2] # limit results to 2 videos
|
63 |
for video in search_results:
|
64 |
st.write(f"[{video.title}]({video.watch_url})")
|
65 |
|