Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,87 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(chatbot_model)
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
11 |
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
17 |
|
18 |
# User Input
|
19 |
-
user_input = st.text_input("
|
20 |
|
21 |
-
if st.button("
|
22 |
if user_input:
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
# Display emotion
|
41 |
-
st.write(f"🧠 **Emotion Detected:** {emotion}")
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# # Load chatbot model
|
5 |
+
# chatbot_model = "microsoft/DialoGPT-medium"
|
6 |
+
# tokenizer = AutoTokenizer.from_pretrained(chatbot_model)
|
7 |
+
# model = AutoModelForCausalLM.from_pretrained(chatbot_model)
|
8 |
+
|
9 |
+
# # Load emotion detection model
|
10 |
+
# emotion_pipeline = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
|
11 |
+
|
12 |
+
# st.title("🧠 Mental Health Chatbot")
|
13 |
+
|
14 |
+
# # Chat history
|
15 |
+
# if "chat_history" not in st.session_state:
|
16 |
+
# st.session_state.chat_history = []
|
17 |
+
|
18 |
+
# # User Input
|
19 |
+
# user_input = st.text_input("You:", key="user_input")
|
20 |
+
|
21 |
+
# if st.button("Send"):
|
22 |
+
# if user_input:
|
23 |
+
# # Generate chatbot response
|
24 |
+
# input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt")
|
25 |
+
# output = model.generate(input_ids, max_length=200, pad_token_id=tokenizer.eos_token_id)
|
26 |
+
# response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
27 |
+
|
28 |
+
# # Detect emotion
|
29 |
+
# emotion_result = emotion_pipeline(user_input)
|
30 |
+
# emotion = emotion_result[0]["label"]
|
31 |
|
32 |
+
# # Store chat history
|
33 |
+
# st.session_state.chat_history.append(("You", user_input))
|
34 |
+
# st.session_state.chat_history.append(("Bot", response))
|
|
|
35 |
|
36 |
+
# # Display chat
|
37 |
+
# for sender, msg in st.session_state.chat_history:
|
38 |
+
# st.write(f"**{sender}:** {msg}")
|
39 |
|
40 |
+
# # Display emotion
|
41 |
+
# st.write(f"🧠 **Emotion Detected:** {emotion}")
|
42 |
|
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 |
+
# Get Emotion Analysis
|
55 |
+
emotion_result = emotion_pipeline(user_input)[0]
|
56 |
+
st.write(f"**Emotion Detected:** {emotion_result['label']} ({emotion_result['score']:.2f})")
|
57 |
+
|
58 |
+
# Get Mental Health Condition Analysis
|
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 |
+
# Chatbot Response using DeepSeek AI
|
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 |
|
|
|
|