File size: 3,440 Bytes
b746dc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92d4fbe
b746dc4
 
 
92d4fbe
b746dc4
 
 
92d4fbe
b746dc4
 
92d4fbe
b746dc4
 
 
2479207
b746dc4
2479207
f0387b2
2479207
 
f8fa7ea
2479207
 
f8fa7ea
2479207
 
 
 
 
 
 
 
 
 
b746dc4
92d4fbe
b746dc4
92d4fbe
b746dc4
92d4fbe
2479207
b746dc4
 
 
2479207
b746dc4
 
 
2479207
 
 
 
 
b746dc4
 
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
84
85
86
87
# import streamlit as st
# from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer

# # Load chatbot model
# chatbot_model = "microsoft/DialoGPT-medium"
# tokenizer = AutoTokenizer.from_pretrained(chatbot_model)
# model = AutoModelForCausalLM.from_pretrained(chatbot_model)

# # Load emotion detection model
# emotion_pipeline = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")

# st.title("🧠 Mental Health Chatbot")

# # Chat history
# if "chat_history" not in st.session_state:
#     st.session_state.chat_history = []

# # User Input
# user_input = st.text_input("You:", key="user_input")

# if st.button("Send"):
#     if user_input:
#         # Generate chatbot response
#         input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt")
#         output = model.generate(input_ids, max_length=200, pad_token_id=tokenizer.eos_token_id)
#         response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)

#         # Detect emotion
#         emotion_result = emotion_pipeline(user_input)
#         emotion = emotion_result[0]["label"]

#         # Store chat history
#         st.session_state.chat_history.append(("You", user_input))
#         st.session_state.chat_history.append(("Bot", response))

#         # Display chat
#         for sender, msg in st.session_state.chat_history:
#             st.write(f"**{sender}:** {msg}")

#         # Display emotion
#         st.write(f"🧠 **Emotion Detected:** {emotion}")



import streamlit as st
from transformers import pipeline, AutoTokenizer

# βœ… Load Emotion Recognition Model
emotion_pipeline = pipeline("text-classification", model="ahmettasdemir/distilbert-base-uncased-finetuned-emotion")

# βœ… Load Stress Detection Model
stress_pipeline = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")

# βœ… Load Mental Disorder Detection Model
mental_bert_pipeline = pipeline("text-classification", model="nlpconnect/vit-gpt2-image-captioning")

# βœ… Load PHQ-9 Depression Severity Classifier
phq9_pipeline = pipeline("text-classification", model="PHQ-9 Depression Classifier")

# βœ… Load Chatbot Model (DeepSeek)
deepseek_model = "deepseek-ai/deepseek-llm-7b"
deepseek_tokenizer = AutoTokenizer.from_pretrained(deepseek_model)
deepseek_pipeline = pipeline("text-generation", model=deepseek_model, tokenizer=deepseek_tokenizer)

# πŸ₯ Streamlit UI
st.title("🧠 Mental Health Assistant Bot")

user_input = st.text_input("How are you feeling today?", "")

if st.button("Submit"):
    if user_input:
        # βœ… Emotion Analysis
        emotion_result = emotion_pipeline(user_input)[0]
        st.write(f"**Emotion Detected:** {emotion_result['label']} ({emotion_result['score']:.2f})")

        # βœ… Stress Level Analysis
        stress_result = stress_pipeline(user_input)[0]
        st.write(f"**Stress Level:** {stress_result['label']} ({stress_result['score']:.2f})")

        # βœ… Mental Health Condition Detection
        mental_health_result = mental_bert_pipeline(user_input)[0]
        st.write(f"**Possible Mental Health Condition:** {mental_health_result['label']} ({mental_health_result['score']:.2f})")

        # βœ… AI Chatbot Response
        deepseek_response = deepseek_pipeline(user_input, max_length=100, do_sample=True)[0]['generated_text']
        st.write(f"πŸ€– **Chatbot:** {deepseek_response}")