MindMate / app.py
SanaAdeel's picture
Update app.py
080c8b0 verified
import streamlit as st
from transformers import pipeline
import random
# Load a text-generation pipeline using DialoGPT for conversation
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
# A list of comforting and supportive responses
comforting_responses = [
"I'm really sorry you're feeling this way, but I'm glad you're reaching out. You're not alone.",
"It’s okay to not be okay sometimes. Take your time and reach out for help when you're ready.",
"Deep breaths. Everything will be okay. You’ve got this!",
"Try focusing on your breathing: inhale deeply for 4 seconds, hold for 4 seconds, and exhale for 4 seconds.",
"You're stronger than you think. Just take things one step at a time.",
"Exercise can really help clear your mind. Even a short walk can make a difference."
]
def offer_advice(user_input):
"""Offer advice based on user input."""
if 'stress' in user_input.lower() or 'overwhelmed' in user_input.lower():
return "Stress can really take a toll. Try taking deep breaths or doing a mindfulness exercise."
elif 'depressed' in user_input.lower():
return "I'm sorry you're feeling this way. Talking to a professional might help, but I’m here for you too."
elif 'suicidal' in user_input.lower():
return "I'm really sorry you're feeling like this, but I encourage you to reach out to a mental health professional or a helpline immediately."
else:
return random.choice(comforting_responses)
# Streamlit UI
st.title("Mental Health Support Chatbot")
st.write("I'm here to listen and offer some support. Let's talk.")
# Input text from the user
user_input = st.text_input("How are you feeling today?", "")
# When the user submits their input
if user_input:
# Provide advice based on the input
advice = offer_advice(user_input)
# Show chatbot response
st.write("Chatbot (Support):", advice)
# Generate a response using DialoGPT (text generation task)
response = chatbot(user_input, max_length=1000, num_return_sequences=1)
# Display the chatbot's response
st.write("Chatbot:", response[0]['generated_text'])
# Add a message for helping users to reach out to professionals
st.write("""
If you're feeling overwhelmed, it might help to talk to a professional. You are not alone, and help is available.
""")