|
|
|
|
|
""" |
|
|
EMERGENCY DEPLOYMENT - Ultra Minimal Mental Health Assistant |
|
|
Only uses gradio and standard library - guaranteed to work on any platform |
|
|
""" |
|
|
|
|
|
import gradio as gr |
|
|
import os |
|
|
import re |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
os.environ['HUGGINGFACE_SPACES'] = '1' |
|
|
|
|
|
|
|
|
RESPONSES = { |
|
|
'crisis': "I'm very concerned about what you're sharing. Please reach out immediately:\n• Emergency: 911\n• Crisis Helpline: 988\n• Text HOME to 741741", |
|
|
'depression': "I hear you're struggling. Depression is treatable and you're not alone. Please consider talking to a mental health professional.", |
|
|
'anxiety': "Anxiety can be overwhelming. Try deep breathing: breathe in for 4, hold for 4, out for 6. Consider professional support.", |
|
|
'stress': "Stress affects us all. Take breaks, practice self-care, and don't hesitate to ask for help when you need it.", |
|
|
'help': "I'm here to listen and provide support. You can talk to me about how you're feeling, and I'll do my best to help.", |
|
|
'default': "Thank you for sharing. I'm here to listen. How are you feeling right now?" |
|
|
} |
|
|
|
|
|
def simple_chat(message, history): |
|
|
"""Ultra-simple keyword-based mental health responses""" |
|
|
if not message: |
|
|
return history |
|
|
|
|
|
message_lower = message.lower() |
|
|
|
|
|
|
|
|
history.append([message, None]) |
|
|
|
|
|
|
|
|
crisis_words = ['suicide', 'kill myself', 'end it all', 'hurt myself', 'die'] |
|
|
if any(word in message_lower for word in crisis_words): |
|
|
response = RESPONSES['crisis'] |
|
|
elif any(word in message_lower for word in ['depressed', 'depression', 'sad', 'hopeless']): |
|
|
response = RESPONSES['depression'] |
|
|
elif any(word in message_lower for word in ['anxious', 'anxiety', 'worried', 'panic']): |
|
|
response = RESPONSES['anxiety'] |
|
|
elif any(word in message_lower for word in ['stress', 'stressed', 'overwhelmed']): |
|
|
response = RESPONSES['stress'] |
|
|
elif any(word in message_lower for word in ['help', 'support', 'guidance']): |
|
|
response = RESPONSES['help'] |
|
|
else: |
|
|
response = RESPONSES['default'] |
|
|
|
|
|
|
|
|
history[-1][1] = response |
|
|
return history |
|
|
|
|
|
|
|
|
with gr.Blocks(title="Mental Health Support", theme=gr.themes.Soft()) as demo: |
|
|
gr.Markdown(""" |
|
|
# 🧠 Mental Health Support Assistant |
|
|
|
|
|
A safe space to talk about your mental health. While I provide basic support, |
|
|
please reach out to professionals for serious concerns. |
|
|
|
|
|
**Crisis Resources:** |
|
|
- Emergency: 911 |
|
|
- National Suicide Prevention Lifeline: 988 |
|
|
- Crisis Text Line: Text HOME to 741741 |
|
|
""") |
|
|
|
|
|
chatbot = gr.Chatbot(height=400) |
|
|
msg = gr.Textbox(placeholder="How are you feeling today?", container=False) |
|
|
|
|
|
msg.submit(simple_chat, [msg, chatbot], [chatbot]) |
|
|
msg.submit(lambda: "", None, [msg]) |
|
|
|
|
|
gr.Markdown(""" |
|
|
### Important Notice |
|
|
This is a basic support tool, not a replacement for professional mental health care. |
|
|
If you're experiencing a mental health emergency, please contact emergency services immediately. |
|
|
""") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("🚀 Starting Emergency Mental Health Assistant") |
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |
|
|
|