CompanAIon / app.py
Bey007's picture
Update app.py
a5fe917 verified
raw
history blame
2.16 kB
import streamlit as st
from transformers import pipeline
import pyttsx3
from youtubesearchpython import VideosSearch
# Set up the Streamlit app
st.set_page_config(page_title="Grief and Loss Support Bot", page_icon="πŸ•ŠοΈ", layout="centered")
# Customizing the app style for a soothing look
st.markdown("""
<style>
.main {
background-color: #F3F7F6;
}
.css-1d391kg {
font-family: 'Arial', sans-serif;
}
</style>
""", unsafe_allow_html=True)
st.title("Grief and Loss Support Bot πŸ•ŠοΈ")
st.subheader("We are here for you. πŸ’š Your companion in tough times")
# Set up the conversational model
try:
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
except Exception as e:
st.error(f"Error loading the model: {e}")
# Set up text-to-speech engine
engine = pyttsx3.init()
engine.setProperty('rate', 150) # Speed of speech
engine.setProperty('volume', 0.9) # Volume level
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) # Choose the desired voice
# 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 response using the model
response = chatbot(user_input, max_length=100)[0]['generated_text']
# Display response and read it aloud
st.write(response)
engine.say(response)
engine.runAndWait()
# Suggest hobbies to uplift the user's mood
hobbies = ["Painting", "Reading books", "Gardening", "Learning a new language", "Playing an instrument"]
st.subheader("Suggested Hobbies")
st.write("Here are some hobbies that might help you feel better:")
for hobby in hobbies:
st.write(f"- {hobby}")
# Search for helpful YouTube videos
st.subheader("Recommended Videos")
video_search = VideosSearch('motivational activities for coping with grief', limit=3)
results = video_search.result()['result']
for video in results:
st.write(f"[{video['title']}]({video['link']})")
st.write("Remember, it's okay to seek support and take small steps towards healing. πŸ’š")