File size: 1,573 Bytes
fd64912
d7596e9
 
fd64912
d7596e9
fd64912
d7596e9
 
f47e491
d7596e9
fd64912
 
d7596e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline
from gtts import gTTS
from youtubesearchpython import VideosSearch
import os

# Initialize the chatbot pipeline using a pre-trained model from Hugging Face
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")

# Streamlit app title
st.title("Grief and Loss Support Bot")

# Text input for user queries
user_input = st.text_input("You:", "")

# Respond to user input
if user_input:
    # Generate a response from the chatbot
    response = chatbot(user_input, max_length=50, num_return_sequences=1)[0]['generated_text']
    st.text_area("Bot:", response, height=100)

    # Convert the response to speech using gTTS and save as an audio file
    tts = gTTS(text=response, lang='en')
    tts.save("response.mp3")
    audio_file = open("response.mp3", "rb")
    audio_bytes = audio_file.read()
    st.audio(audio_bytes, format="audio/mp3")
    audio_file.close()
    os.remove("response.mp3")  # Clean up the audio file after playback

# YouTube search functionality for coping resources
st.header("Helpful Videos")
search_query = st.text_input("Enter a topic for video suggestions:")
if search_query:
    # Search for videos using YouTubeSearchPython
    video_search = VideosSearch(search_query, limit=3)
    results = video_search.result()
    for video in results['result']:
        st.write(f"[{video['title']}]({video['link']})")

# Display a note for users
st.write("**Note:** This bot is designed for general emotional support. For urgent help, please reach out to professional resources.")