Spaces:
Sleeping
Sleeping
import streamlit as st | |
from llama_cpp import Llama | |
from gtts import gTTS | |
from pytube import Search | |
import random | |
import os | |
# Initialize the Llama model by specifying the model path | |
llm = Llama(model_path="HyunCello-KULLM3-empathy-v1.0-IQ4_XS.gguf") | |
# Configure Streamlit page | |
st.set_page_config(page_title="Grief & Loss Support Bot", page_icon="๐ฑ", layout="centered") | |
st.markdown(""" | |
<style> | |
.main { background-color: #F4F9F9; } | |
h1, h2, h3, h4 { color: #4C6D7D; } | |
.stTextInput>div>div>input { background-color: #E8F1F2; border-radius: 5px; } | |
.stButton>button { background-color: #A4D4AE; color: white; } | |
.stButton>button:hover { background-color: #92C8A6; } | |
</style> | |
""", unsafe_allow_html=True) | |
# Title and description | |
st.title("Grief & Loss Support Bot ๐ฑ") | |
st.subheader("Your compassionate companion in tough times ๐") | |
# User input | |
user_input = st.text_input("How are you feeling today?", placeholder="Share your thoughts here...", max_chars=500) | |
# Generate empathetic response using Llama model | |
if user_input: | |
response = llm( | |
messages=[ | |
{"role": "user", "content": user_input} | |
] | |
)['choices'][0]['message']['content'] | |
# Display empathetic response | |
st.text_area("Bot's Response:", response, height=150) | |
# Convert text to speech for added comfort | |
tts = gTTS(response, lang='en') | |
audio_file = "response.mp3" | |
tts.save(audio_file) | |
st.audio(audio_file, format="audio/mp3") | |
# Suggested activities based on user input | |
activity_suggestions = { | |
"positive": ["try journaling your feelings", "practice yoga", "learn a new recipe"], | |
"neutral": ["take a short walk", "listen to calming music", "try some mindful breathing"], | |
"negative": ["explore creative activities like painting", "watch a motivational video", "write down small goals to feel organized"] | |
} | |
activities = activity_suggestions["neutral"] # Default to "neutral" for simplicity | |
# Show dynamic activity suggestion | |
st.info("Hereโs something you could try to lift your spirits:") | |
selected_activity = random.choice(activities) | |
st.write(f"**Activity Suggestion:** {selected_activity}") | |
# YouTube search for video resources | |
search = Search(selected_activity) | |
st.write("Recommended Videos:") | |
for video in search.results[:2]: # Display top 2 videos | |
st.write(f"[{video.title}]({video.watch_url})") | |
# Crisis response if critical keywords are detected | |
crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"] | |
if any(keyword in user_input.lower() for keyword in crisis_keywords): | |
st.error("It sounds like you're going through a very tough time. Please don't hesitate to reach out for help.") | |
st.write("[Click here for emergency resources](https://www.helpguide.org/find-help.htm)") | |