Spaces:
Running
Running
Download app.py from bish17/mental-health-bot-space: direct link, hf CLI and curl.
- Browser
- Download file 875 Bytes
-
https://huggingface.co/spaces/bish17/mental-health-bot-space/resolve/main/app.py
- Command line
-
hf download hf://spaces/bish17/mental-health-bot-space/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bish17/mental-health-bot-space/resolve/main/app.py
875 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Load pre-trained models | |
| emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") | |
| severity_model = pipeline("text-classification", model="bhadresh-savani/bert-base-uncased-emotion") | |
| dialog_model = pipeline("text-generation", model="microsoft/DialoGPT-medium") | |
| def chatbot(user_input): | |
| emotion = emotion_model(user_input)[0]['label'] | |
| severity = severity_model(user_input)[0]['label'] | |
| reply = dialog_model(user_input, max_length=50, num_return_sequences=1)[0]['generated_text'] | |
| return f"Emotion: {emotion}\nSeverity: {severity}\nBot Reply: {reply}" | |
| iface = gr.Interface( | |
| fn=chatbot, | |
| inputs="text", | |
| outputs="text", | |
| title="Mental Health Bot", | |
| description="Detects emotion & severity, then replies with supportive text." | |
| ) | |
| iface.launch() | |