Spaces:
Sleeping
Sleeping
Initial commit
Browse files- .DS_Store +0 -0
- .huggingface/spaces.yml +9 -0
- app.py +5 -3
- chat_log_combined.csv +0 -19
- Kaggle_Mental_Health_Conversations_train.csv → dataset/Kaggle_Mental_Health_Conversations_train.csv +0 -0
- logs/.DS_Store +0 -0
- logs/chat_log_combined.csv +12 -0
- Flan-T5_on_Kaggle_Dataset.ipynb → notebooks/Flan-T5_on_Kaggle_Dataset.ipynb +0 -0
- ML_on_Kaggle_Dataset.ipynb → notebooks/ML_on_Kaggle_Dataset.ipynb +0 -0
- Mistral-7B_on_Kaggle_Dataset.ipynb → notebooks/Mistral-7B_on_Kaggle_Dataset.ipynb +0 -0
- requirements.txt +1 -3
- utils/__pycache__/helper_functions.cpython-310.pyc +0 -0
- utils/helper_functions.py +65 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.huggingface/spaces.yml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
title: Counselor Assistant
|
2 |
+
emoji: 🧠
|
3 |
+
colorFrom: purple
|
4 |
+
colorTo: blue
|
5 |
+
sdk: streamlit
|
6 |
+
sdk_version: 1.32.2
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
import pandas as pd
|
4 |
import json
|
@@ -36,7 +37,7 @@ This tool is here to offer **supportive, AI-generated suggestions** when you’r
|
|
36 |
It's a sidekick, not a substitute for your clinical judgment 💚
|
37 |
""")
|
38 |
|
39 |
-
df = pd.read_csv("Kaggle_Mental_Health_Conversations_train.csv")
|
40 |
df = df[['Context', 'Response']].dropna().copy()
|
41 |
|
42 |
keywords_to_labels = {
|
@@ -112,7 +113,7 @@ def trim_memory(history, max_turns=6):
|
|
112 |
|
113 |
def save_conversation(history):
|
114 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
115 |
-
with open("chat_log_combined.csv", "w", newline='') as f:
|
116 |
writer = csv.writer(f)
|
117 |
writer.writerow(["Timestamp", "Role", "Content", "Intent", "Confidence"])
|
118 |
for entry in history:
|
@@ -170,6 +171,7 @@ for turn in st.session_state.history:
|
|
170 |
if turn["role"] == "user":
|
171 |
st.markdown(f"🧍♀️ **Patient:** {turn['content']}")
|
172 |
else:
|
173 |
-
st.markdown(f"
|
174 |
st.caption(f"_Intent: {turn['label']} (Confidence: {turn['confidence']:.0%})_")
|
175 |
st.markdown("---")
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from utils.helper_functions import *
|
3 |
import os
|
4 |
import pandas as pd
|
5 |
import json
|
|
|
37 |
It's a sidekick, not a substitute for your clinical judgment 💚
|
38 |
""")
|
39 |
|
40 |
+
df = pd.read_csv("dataset/Kaggle_Mental_Health_Conversations_train.csv")
|
41 |
df = df[['Context', 'Response']].dropna().copy()
|
42 |
|
43 |
keywords_to_labels = {
|
|
|
113 |
|
114 |
def save_conversation(history):
|
115 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
116 |
+
with open("logs/chat_log_combined.csv", "w", newline='') as f:
|
117 |
writer = csv.writer(f)
|
118 |
writer.writerow(["Timestamp", "Role", "Content", "Intent", "Confidence"])
|
119 |
for entry in history:
|
|
|
171 |
if turn["role"] == "user":
|
172 |
st.markdown(f"🧍♀️ **Patient:** {turn['content']}")
|
173 |
else:
|
174 |
+
st.markdown(f"👨⚕️ **Suggested Counselor Response:** {turn['content']}")
|
175 |
st.caption(f"_Intent: {turn['label']} (Confidence: {turn['confidence']:.0%})_")
|
176 |
st.markdown("---")
|
177 |
+
|
chat_log_combined.csv
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
Timestamp,Role,Content,Intent,Confidence
|
2 |
-
2025-04-11 03:11:14,user,i am nervous about my incoming interview ,,0.0
|
3 |
-
2025-04-11 03:11:14,assistant,"From a mental health perspective, it is understandable that the patient may be feeling nervous about their upcoming interview. Anxiety is a common and natural response to stressful situations, and it can manifest in various physical and emotional symptoms.
|
4 |
-
|
5 |
-
The patient's nervousness may be related to their fear of failure, uncertainty about the interview process, or concerns about their ability to perform well. These feelings of anxiety may be affecting their self-confidence, sleep, appetite, and overall well-being.
|
6 |
-
|
7 |
-
It is important for the patient to acknowledge and validate their feelings, and to take steps to manage their anxiety. Some effective coping strategies for managing anxiety include deep breathing exercises, progressive muscle relaxation, cognitive-behavioral therapy, and mindfulness practices. It may also be helpful for the patient to practice positive self-talk and visualization techniques to boost their confidence and self-esteem.
|
8 |
-
|
9 |
-
Overall, it is essential for the patient to prioritize their mental health and well-being during this time, and to seek support from friends, family, or a mental health professional if needed.",information,0.84
|
10 |
-
2025-04-11 03:11:14,user,i cannot sleep ,,0.0
|
11 |
-
2025-04-11 03:11:14,assistant,"There can be a variety of reasons why someone might have trouble sleeping from a mental health perspective. Some common causes include:
|
12 |
-
|
13 |
-
1. Stress and anxiety: High levels of stress and anxiety can interfere with the ability to fall and stay asleep. This can be caused by a number of factors, such as work or family problems, financial difficulties, or health concerns.
|
14 |
-
2. Depression: Depression can cause changes in sleep patterns, including difficulty falling and staying asleep, or feeling tired during the day.
|
15 |
-
3. Bipolar disorder: Bipolar disorder is a mental health condition characterized by extreme mood swings, including periods of depression and mania. Sleep disturbances are common in people with bipolar disorder.
|
16 |
-
4. Post-traumatic stress disorder (PTSD): PTSD is a mental health condition that can develop after experiencing or witnessing a traumatic event, such as a natural disaster, a serious accident, or a sexual assault. People with PTSD may have difficulty sleeping, as they may be haunted by memories of the event.
|
17 |
-
5. Substance abuse: The use of drugs and alcohol can interfere with sleep, making it difficult to fall and stay asleep.
|
18 |
-
|
19 |
-
It is important to note that these are just a few examples, and that there may be other underlying factors that are contributing to the difficulty sleeping. If the patient is experiencing persistent difficulty sleeping, it may be helpful to seek professional help",information,0.85
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kaggle_Mental_Health_Conversations_train.csv → dataset/Kaggle_Mental_Health_Conversations_train.csv
RENAMED
File without changes
|
logs/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
logs/chat_log_combined.csv
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Timestamp,Role,Content,Intent,Confidence
|
2 |
+
2025-04-11 04:03:53,user,i'm sick physically and mentall ,,0.0
|
3 |
+
2025-04-11 04:03:53,assistant,"A person who says they are sick physically and mentally may be experiencing a range of symptoms and conditions that could be affecting their mental health. Some possible factors that could contribute to this might include:
|
4 |
+
|
5 |
+
1. Stress: Chronic stress can cause physical symptoms such as muscle tension, headaches, and fatigue, as well as mental symptoms such as anxiety, depression, and difficulty sleeping.
|
6 |
+
2. Depression: Depression is a common mental health disorder that can cause physical symptoms such as fatigue and decreased appetite, as well as mental symptoms such as sadness, hopelessness, and difficulty concentrating.
|
7 |
+
3. Anxiety: Anxiety is another common mental health disorder that can cause physical symptoms such as sweating, trembling, and difficulty breathing, as well as mental symptoms such as worry, fear, and avoidance.
|
8 |
+
4. Trauma: Traumatic experiences, such as abuse, neglect, or natural disasters, can cause mental health symptoms such as anxiety, depression, and difficulty trusting others.
|
9 |
+
5. Substance use: The use of drugs or alcohol can have a negative impact on mental health, leading to symptoms such as depression, anxiety, and difficulty functioning in daily life.
|
10 |
+
6. Bipolar disorder: Bipolar disorder is a mental health condition characterized by extreme mood swings, including periods of intense happiness (mania) and intense sadness (depression).
|
11 |
+
|
12 |
+
It's important to",information,0.85
|
Flan-T5_on_Kaggle_Dataset.ipynb → notebooks/Flan-T5_on_Kaggle_Dataset.ipynb
RENAMED
File without changes
|
ML_on_Kaggle_Dataset.ipynb → notebooks/ML_on_Kaggle_Dataset.ipynb
RENAMED
File without changes
|
Mistral-7B_on_Kaggle_Dataset.ipynb → notebooks/Mistral-7B_on_Kaggle_Dataset.ipynb
RENAMED
File without changes
|
requirements.txt
CHANGED
@@ -2,6 +2,4 @@ streamlit
|
|
2 |
pandas
|
3 |
scikit-learn
|
4 |
xgboost
|
5 |
-
|
6 |
-
matplotlib
|
7 |
-
llama-cpp-python --prefer-binary
|
|
|
2 |
pandas
|
3 |
scikit-learn
|
4 |
xgboost
|
5 |
+
llama-cpp-python==0.2.24
|
|
|
|
utils/__pycache__/helper_functions.cpython-310.pyc
ADDED
Binary file (2.8 kB). View file
|
|
utils/helper_functions.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# utils/helper_functions.py
|
2 |
+
|
3 |
+
import time
|
4 |
+
import json
|
5 |
+
import csv
|
6 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
7 |
+
from sklearn.preprocessing import LabelEncoder
|
8 |
+
|
9 |
+
# Labeling logic
|
10 |
+
keywords_to_labels = {
|
11 |
+
'advice': ['try', 'should', 'suggest', 'recommend'],
|
12 |
+
'validation': ['understand', 'feel', 'valid', 'normal'],
|
13 |
+
'information': ['cause', 'often', 'disorder', 'symptom'],
|
14 |
+
'question': ['how', 'what', 'why', 'have you']
|
15 |
+
}
|
16 |
+
|
17 |
+
def auto_label_response(response):
|
18 |
+
response = response.lower()
|
19 |
+
for label, keywords in keywords_to_labels.items():
|
20 |
+
if any(word in response for word in keywords):
|
21 |
+
return label
|
22 |
+
return 'information'
|
23 |
+
|
24 |
+
def build_prompt(user_input, response_type):
|
25 |
+
prompts = {
|
26 |
+
"advice": f"A patient said: \"{user_input}\". What advice should a mental health counselor give to support them?",
|
27 |
+
"validation": f"A patient said: \"{user_input}\". How can a counselor validate and empathize with their emotions?",
|
28 |
+
"information": f"A patient said: \"{user_input}\". Explain what might be happening from a mental health perspective.",
|
29 |
+
"question": f"A patient said: \"{user_input}\". What thoughtful follow-up questions should a counselor ask?"
|
30 |
+
}
|
31 |
+
return prompts.get(response_type, prompts["information"])
|
32 |
+
|
33 |
+
def predict_response_type(user_input, model, vectorizer, label_encoder):
|
34 |
+
vec = vectorizer.transform([user_input])
|
35 |
+
pred = model.predict(vec)
|
36 |
+
proba = model.predict_proba(vec).max()
|
37 |
+
label = label_encoder.inverse_transform(pred)[0]
|
38 |
+
return label, proba
|
39 |
+
|
40 |
+
def generate_llm_response(prompt, llm):
|
41 |
+
start = time.time()
|
42 |
+
result = llm(prompt, max_tokens=300, temperature=0.7)
|
43 |
+
end = time.time()
|
44 |
+
elapsed = round(end - start, 1)
|
45 |
+
return result['choices'][0]['text'].strip(), elapsed
|
46 |
+
|
47 |
+
def trim_memory(history, max_turns=6):
|
48 |
+
return history[-max_turns * 2:]
|
49 |
+
|
50 |
+
def save_conversation(history):
|
51 |
+
timestamp = time.strftime("%Y%m%d-%H%M%S")
|
52 |
+
file_name = f"chat_log_{timestamp}.csv"
|
53 |
+
with open(file_name, "w", newline='') as f:
|
54 |
+
writer = csv.writer(f)
|
55 |
+
writer.writerow(["Role", "Content", "Intent", "Confidence"])
|
56 |
+
for turn in history:
|
57 |
+
writer.writerow([
|
58 |
+
turn.get("role", ""),
|
59 |
+
turn.get("content", ""),
|
60 |
+
turn.get("label", ""),
|
61 |
+
round(float(turn.get("confidence", 0)) * 100)
|
62 |
+
])
|
63 |
+
print(f"Saved to {file_name}")
|
64 |
+
return file_name
|
65 |
+
|