File size: 2,877 Bytes
fd64912
06bf795
d7596e9
b1dc82e
fd64912
06bf795
b1dc82e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd64912
b1dc82e
 
 
 
06bf795
 
 
 
 
 
 
 
 
 
 
 
b1dc82e
 
d7596e9
 
06bf795
 
 
 
 
 
b1dc82e
06bf795
 
 
 
 
 
 
 
 
b1dc82e
06bf795
 
 
 
 
b1dc82e
06bf795
 
 
 
 
 
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
86
87
88
import streamlit as st
import torch
from transformers import pipeline
from youtubesearchpython import VideosSearch

# Set up the page configuration for a welcoming appearance
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")

# Load the conversational model pipeline
try:
    conversational_pipeline = pipeline(task="conversational", model="microsoft/DialoGPT-medium")
except Exception as e:
    st.error(f"Error loading the conversational model: {e}")

# Load the TTS pipeline for generating audio
try:
    tts = pipeline(task="text-to-audio", model="espnet/kan-bayashi_ljspeech_vits", device=0 if torch.cuda.is_available() else -1)
except Exception as e:
    st.error(f"Error loading the TTS model: {e}")

# 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 conversational response
    response = conversational_pipeline(user_input)
    response_text = response[0]['generated_text']
    
    st.write("Bot's Response:")
    st.write(response_text)

    # Generate audio from the response text
    try:
        audio_output = tts(response_text)
        audio_file_path = "response_audio.wav"
        with open(audio_file_path, "wb") as f:
            f.write(audio_output["audio"])
        st.audio(audio_file_path)
    except Exception as e:
        st.error(f"Error generating audio: {e}")

    # Provide hobby suggestions
    st.markdown("### Suggested Hobbies and Activities")
    hobby_prompt = "Suggest hobbies and activities for emotional well-being:"
    hobby_response = pipeline("text-generation", model="gpt2")(hobby_prompt, max_length=50, num_return_sequences=1)
    st.write(hobby_response[0]['generated_text'])

    # Search for coping videos on YouTube
    st.markdown("### Informational YouTube Videos")
    video_search = VideosSearch('productive hobbies and coping with grief', limit=3)
    results = video_search.result()
    for video in results['result']:
        st.write(f"[{video['title']}]({video['link']})")