File size: 2,156 Bytes
fd64912
a5fe917
09abbb7
a5fe917
fd64912
a5fe917
b1dc82e
 
a5fe917
b1dc82e
 
a5fe917
b1dc82e
 
a5fe917
 
b1dc82e
 
 
fd64912
b1dc82e
 
 
a5fe917
06bf795
a5fe917
06bf795
a5fe917
06bf795
a5fe917
 
 
 
 
 
06bf795
b1dc82e
 
d7596e9
 
a5fe917
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1dc82e
a5fe917
 
b1dc82e
a5fe917
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
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. πŸ’š")