Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,45 +43,44 @@
|
|
| 43 |
|
| 44 |
|
| 45 |
import streamlit as st
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
st.title("🧠 Mental Health Assistant Bot")
|
| 48 |
|
| 49 |
-
# User Input
|
| 50 |
user_input = st.text_input("How are you feeling today?", "")
|
| 51 |
|
| 52 |
if st.button("Submit"):
|
| 53 |
if user_input:
|
| 54 |
-
#
|
| 55 |
emotion_result = emotion_pipeline(user_input)[0]
|
| 56 |
st.write(f"**Emotion Detected:** {emotion_result['label']} ({emotion_result['score']:.2f})")
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
mental_health_result = mental_bert_pipeline(user_input)[0]
|
| 60 |
-
st.write(f"**Possible Mental Health Condition:** {mental_health_result['label']} ({mental_health_result['score']:.2f})")
|
| 61 |
-
|
| 62 |
-
# Get Stress Level Analysis
|
| 63 |
stress_result = stress_pipeline(user_input)[0]
|
| 64 |
st.write(f"**Stress Level:** {stress_result['label']} ({stress_result['score']:.2f})")
|
| 65 |
|
| 66 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
deepseek_response = deepseek_pipeline(user_input, max_length=100, do_sample=True)[0]['generated_text']
|
| 68 |
st.write(f"🤖 **Chatbot:** {deepseek_response}")
|
| 69 |
-
|
| 70 |
-
# Question Answering Section
|
| 71 |
-
st.subheader("Ask Mental Health Questions")
|
| 72 |
-
user_question = st.text_input("Ask me anything about mental health:", "")
|
| 73 |
-
|
| 74 |
-
if st.button("Ask"):
|
| 75 |
-
if user_question:
|
| 76 |
-
answer = qa_pipeline(question=user_question, context="Mental health is important for overall well-being.")
|
| 77 |
-
st.write(f"**Answer:** {answer['answer']}")
|
| 78 |
-
|
| 79 |
-
# PHQ-9 Depression Assessment
|
| 80 |
-
st.subheader("Depression Severity Assessment (PHQ-9)")
|
| 81 |
-
phq9_question = st.text_input("Describe your mood over the last two weeks:", "")
|
| 82 |
-
|
| 83 |
-
if st.button("Analyze Depression Level"):
|
| 84 |
-
if phq9_question:
|
| 85 |
-
phq9_result = phq9_pipeline(phq9_question)[0]
|
| 86 |
-
st.write(f"**PHQ-9 Score Suggests:** {phq9_result['label']} ({phq9_result['score']:.2f})")
|
| 87 |
-
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
import streamlit as st
|
| 46 |
+
from transformers import pipeline, AutoTokenizer
|
| 47 |
|
| 48 |
+
# ✅ Load Emotion Recognition Model
|
| 49 |
+
emotion_pipeline = pipeline("text-classification", model="distilbert-base-uncased-finetuned-emotion")
|
| 50 |
+
|
| 51 |
+
# ✅ Load Stress Detection Model
|
| 52 |
+
stress_pipeline = pipeline("text-classification", model="mental-health-roberta")
|
| 53 |
+
|
| 54 |
+
# ✅ Load Mental Disorder Detection Model
|
| 55 |
+
mental_bert_pipeline = pipeline("text-classification", model="mental-bert")
|
| 56 |
+
|
| 57 |
+
# ✅ Load PHQ-9 Depression Severity Classifier
|
| 58 |
+
phq9_pipeline = pipeline("text-classification", model="PHQ-9 Depression Classifier")
|
| 59 |
+
|
| 60 |
+
# ✅ Load Chatbot Model (DeepSeek)
|
| 61 |
+
deepseek_model = "deepseek-ai/deepseek-llm-7b"
|
| 62 |
+
deepseek_tokenizer = AutoTokenizer.from_pretrained(deepseek_model)
|
| 63 |
+
deepseek_pipeline = pipeline("text-generation", model=deepseek_model, tokenizer=deepseek_tokenizer)
|
| 64 |
+
|
| 65 |
+
# 🏥 Streamlit UI
|
| 66 |
st.title("🧠 Mental Health Assistant Bot")
|
| 67 |
|
|
|
|
| 68 |
user_input = st.text_input("How are you feeling today?", "")
|
| 69 |
|
| 70 |
if st.button("Submit"):
|
| 71 |
if user_input:
|
| 72 |
+
# ✅ Emotion Analysis
|
| 73 |
emotion_result = emotion_pipeline(user_input)[0]
|
| 74 |
st.write(f"**Emotion Detected:** {emotion_result['label']} ({emotion_result['score']:.2f})")
|
| 75 |
|
| 76 |
+
# ✅ Stress Level Analysis
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
stress_result = stress_pipeline(user_input)[0]
|
| 78 |
st.write(f"**Stress Level:** {stress_result['label']} ({stress_result['score']:.2f})")
|
| 79 |
|
| 80 |
+
# ✅ Mental Health Condition Detection
|
| 81 |
+
mental_health_result = mental_bert_pipeline(user_input)[0]
|
| 82 |
+
st.write(f"**Possible Mental Health Condition:** {mental_health_result['label']} ({mental_health_result['score']:.2f})")
|
| 83 |
+
|
| 84 |
+
# ✅ AI Chatbot Response
|
| 85 |
deepseek_response = deepseek_pipeline(user_input, max_length=100, do_sample=True)[0]['generated_text']
|
| 86 |
st.write(f"🤖 **Chatbot:** {deepseek_response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|