Spaces:
Sleeping
Sleeping
# Install necessary libraries | |
# pip install streamlit transformers datasets | |
import streamlit as st | |
from transformers import pipeline | |
# Load pre-trained model from Hugging Face | |
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2") | |
# Define the function to analyze emotions and suggest strategies | |
def analyze_and_suggest(responses): | |
suggestions = [] | |
for response in responses: | |
# Get the sentiment analysis result | |
result = emotion_analyzer(response)[0] | |
label = result['label'] | |
# Suggest strategies based on sentiment | |
if label == "NEGATIVE": | |
suggestions.append("Try deep breathing exercises or mindfulness activities.") | |
elif label == "POSITIVE": | |
suggestions.append("Great! Keep the positivity going with a walk or some light exercise.") | |
else: | |
suggestions.append("Consider focusing on better sleep or reflecting on your priorities.") | |
return suggestions | |
# Streamlit App | |
st.title("Personalized Self-Care Strategy App") | |
st.markdown("### Answer the following questions to get personalized self-care suggestions.") | |
# List of questions | |
questions = [ | |
"1. How do you feel about your overall health today?", | |
"2. How have you been sleeping recently?", | |
"3. Do you feel overwhelmed with tasks or emotions?", | |
"4. What are your energy levels like today?", | |
"5. How often do you exercise or engage in physical activity?" | |
] | |
# Collect user inputs | |
responses = [] | |
for question in questions: | |
responses.append(st.text_input(question, placeholder="Type your response here...")) | |
# Button to analyze and provide suggestions | |
if st.button("Get Self-Care Suggestions"): | |
if all(responses): # Ensure all questions are answered | |
suggestions = analyze_and_suggest(responses) | |
st.markdown("### **Your Personalized Suggestions**") | |
for i, suggestion in enumerate(suggestions, 1): | |
st.write(f"**{i}.** {suggestion}") | |
else: | |
st.error("Please answer all the questions before proceeding.") | |