| import streamlit as st |
| from transformers import pipeline |
| import random |
|
|
| |
| chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium") |
|
|
| |
| 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) |
|
|
| |
| st.title("Mental Health Support Chatbot") |
| st.write("I'm here to listen and offer some support. Let's talk.") |
|
|
| |
| user_input = st.text_input("How are you feeling today?", "") |
|
|
| |
| if user_input: |
| |
| advice = offer_advice(user_input) |
| |
| |
| st.write("Chatbot (Support):", advice) |
| |
| |
| response = chatbot(user_input, max_length=1000, num_return_sequences=1) |
| |
| |
| st.write("Chatbot:", response[0]['generated_text']) |
| |
| |
| st.write(""" |
| If you're feeling overwhelmed, it might help to talk to a professional. You are not alone, and help is available. |
| """) |
|
|