Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,9 @@
|
|
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 |
-
#
|
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
|
@@ -43,42 +39,49 @@ st.markdown("""
|
|
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
|
51 |
-
response =
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
audio_file = "response.mp3"
|
57 |
-
tts.save(audio_file)
|
58 |
-
st.audio(audio_file, format="audio/mp3", use_container_width=True)
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
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 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
# Clean up the audio file after playback
|
83 |
-
if os.path.exists(audio_file):
|
84 |
-
os.remove(audio_file)
|
|
|
1 |
import streamlit as st
|
2 |
+
import torch
|
3 |
from transformers import pipeline
|
|
|
|
|
4 |
from youtubesearchpython import VideosSearch
|
5 |
|
6 |
+
# Set up the page configuration for a welcoming appearance
|
|
|
|
|
|
|
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 and modern look
|
|
|
39 |
st.title("Grief and Loss Support Bot ποΈ")
|
40 |
st.subheader("We are here for you. π Your companion in tough times")
|
41 |
|
42 |
+
# Load the conversational model pipeline
|
43 |
+
try:
|
44 |
+
conversational_pipeline = pipeline(task="conversational", model="microsoft/DialoGPT-medium")
|
45 |
+
except Exception as e:
|
46 |
+
st.error(f"Error loading the conversational model: {e}")
|
47 |
+
|
48 |
+
# Load the TTS pipeline for generating audio
|
49 |
+
try:
|
50 |
+
tts = pipeline(task="text-to-audio", model="espnet/kan-bayashi_ljspeech_vits", device=0 if torch.cuda.is_available() else -1)
|
51 |
+
except Exception as e:
|
52 |
+
st.error(f"Error loading the TTS model: {e}")
|
53 |
+
|
54 |
# User input for conversation
|
55 |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
56 |
|
57 |
if user_input:
|
58 |
+
# Generate a conversational response
|
59 |
+
response = conversational_pipeline(user_input)
|
60 |
+
response_text = response[0]['generated_text']
|
61 |
+
|
62 |
+
st.write("Bot's Response:")
|
63 |
+
st.write(response_text)
|
|
|
|
|
|
|
64 |
|
65 |
+
# Generate audio from the response text
|
66 |
+
try:
|
67 |
+
audio_output = tts(response_text)
|
68 |
+
audio_file_path = "response_audio.wav"
|
69 |
+
with open(audio_file_path, "wb") as f:
|
70 |
+
f.write(audio_output["audio"])
|
71 |
+
st.audio(audio_file_path)
|
72 |
+
except Exception as e:
|
73 |
+
st.error(f"Error generating audio: {e}")
|
74 |
|
75 |
+
# Provide hobby suggestions
|
76 |
+
st.markdown("### Suggested Hobbies and Activities")
|
77 |
+
hobby_prompt = "Suggest hobbies and activities for emotional well-being:"
|
78 |
+
hobby_response = pipeline("text-generation", model="gpt2")(hobby_prompt, max_length=50, num_return_sequences=1)
|
79 |
+
st.write(hobby_response[0]['generated_text'])
|
|
|
|
|
|
|
80 |
|
81 |
+
# Search for coping videos on YouTube
|
82 |
+
st.markdown("### Informational YouTube Videos")
|
83 |
+
video_search = VideosSearch('productive hobbies and coping with grief', limit=3)
|
84 |
+
results = video_search.result()
|
85 |
+
for video in results['result']:
|
86 |
+
st.write(f"[{video['title']}]({video['link']})")
|
87 |
|
|
|
|
|
|