File size: 3,332 Bytes
c27fe24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
"""
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

# Set HF Spaces environment
os.environ['HUGGINGFACE_SPACES'] = '1'

# Mental health response patterns
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()
    
    # Add user message
    history.append([message, None])
    
    # Crisis detection
    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']
    
    # Add bot response
    history[-1][1] = response
    return history

# Create interface
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)