CompanAIon / app.py
Bey007's picture
Update app.py
d7596e9 verified
raw
history blame
1.57 kB
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.")