Spaces:
Sleeping
Sleeping
# 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 | |
st.title("🧠 Mental Health Assistant Bot") | |
# User Input | |
user_input = st.text_input("How are you feeling today?", "") | |
if st.button("Submit"): | |
if user_input: | |
# Get Emotion Analysis | |
emotion_result = emotion_pipeline(user_input)[0] | |
st.write(f"**Emotion Detected:** {emotion_result['label']} ({emotion_result['score']:.2f})") | |
# Get Mental Health Condition Analysis | |
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})") | |
# Get Stress Level Analysis | |
stress_result = stress_pipeline(user_input)[0] | |
st.write(f"**Stress Level:** {stress_result['label']} ({stress_result['score']:.2f})") | |
# Chatbot Response using DeepSeek AI | |
deepseek_response = deepseek_pipeline(user_input, max_length=100, do_sample=True)[0]['generated_text'] | |
st.write(f"🤖 **Chatbot:** {deepseek_response}") | |
# Question Answering Section | |
st.subheader("Ask Mental Health Questions") | |
user_question = st.text_input("Ask me anything about mental health:", "") | |
if st.button("Ask"): | |
if user_question: | |
answer = qa_pipeline(question=user_question, context="Mental health is important for overall well-being.") | |
st.write(f"**Answer:** {answer['answer']}") | |
# PHQ-9 Depression Assessment | |
st.subheader("Depression Severity Assessment (PHQ-9)") | |
phq9_question = st.text_input("Describe your mood over the last two weeks:", "") | |
if st.button("Analyze Depression Level"): | |
if phq9_question: | |
phq9_result = phq9_pipeline(phq9_question)[0] | |
st.write(f"**PHQ-9 Score Suggests:** {phq9_result['label']} ({phq9_result['score']:.2f})") | |