Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
from gtts import gTTS | |
import os | |
from youtubesearchpython import VideosSearch | |
# Initialize the conversational model | |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium") | |
# Streamlit app layout with positive, calming design | |
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="ποΈ", layout="centered") | |
# Customizing the app style for a soothing and modern look | |
st.markdown(""" | |
<style> | |
.css-1d391kg { | |
background-color: #F3F7F6; | |
} | |
.css-ffhzg2 { | |
font-size: 1.5em; | |
font-weight: 500; | |
color: #4C6D7D; | |
} | |
.stTextInput>div>div>input { | |
background-color: #D8E3E2; | |
} | |
.stButton>button { | |
background-color: #A9D0B6; | |
color: white; | |
border-radius: 5px; | |
border: none; | |
} | |
.stButton>button:hover { | |
background-color: #8FB79A; | |
} | |
.stTextInput>div>label { | |
color: #4C6D7D; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# Title and introduction | |
st.title("Grief and Loss Support Bot ποΈ") | |
st.subheader("We are here for you. π Your companion in tough times") | |
# User input for conversation | |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500) | |
if user_input: | |
# Generate a compassionate response from the bot | |
response = chatbot(user_input, max_length=150)[0]['generated_text'] | |
st.text_area("Bot's Response:", response, height=150) | |
# Empathetic voice output using gTTS | |
tts = gTTS(response, lang='en') | |
audio_file = "response.mp3" | |
tts.save(audio_file) | |
st.audio(audio_file, format="audio/mp3", use_container_width=True) | |
# Crisis keyword detection for emergency help | |
crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"] | |
if any(keyword in user_input.lower() for keyword in crisis_keywords): | |
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.") | |
st.write("[Find emergency resources here](https://www.helpguide.org/find-help.htm)") | |
# Productive hobby suggestions | |
if st.button("Need something to do? Here are some activities to help you cope:"): | |
st.write("- Journaling your thoughts and emotions π") | |
st.write("- Painting or drawing your feelings π¨") | |
st.write("- Taking a walk in nature π³") | |
st.write("- Listening to soothing music πΆ") | |
st.write("- Practicing deep breathing or meditation π§") | |
st.write("- Trying out a new hobby like knitting or gardening π±") | |
# YouTube content suggestions for coping with grief | |
if st.button("Here are some videos that may help you:"): | |
videos_search = VideosSearch('coping with grief', limit=3) | |
results = videos_search.result()['result'] | |
for i, video in enumerate(results): | |
st.write(f"{i + 1}. [{video['title']}]({video['link']})") | |
# Clean up the audio file after playback | |
if os.path.exists(audio_file): | |
os.remove(audio_file) | |