Spaces:
Sleeping
Sleeping
File size: 3,119 Bytes
fd64912 d7596e9 b1dc82e fd64912 b1dc82e d7596e9 f47e491 b1dc82e fd64912 b1dc82e d7596e9 b1dc82e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
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)
|