Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Install necessary libraries
|
2 |
+
# pip install streamlit transformers datasets
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Load pre-trained model from Hugging Face
|
8 |
+
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2")
|
9 |
+
|
10 |
+
# Define the function to analyze emotions and suggest strategies
|
11 |
+
def analyze_and_suggest(responses):
|
12 |
+
suggestions = []
|
13 |
+
for response in responses:
|
14 |
+
# Get the sentiment analysis result
|
15 |
+
result = emotion_analyzer(response)[0]
|
16 |
+
label = result['label']
|
17 |
+
|
18 |
+
# Suggest strategies based on sentiment
|
19 |
+
if label == "NEGATIVE":
|
20 |
+
suggestions.append("Try deep breathing exercises or mindfulness activities.")
|
21 |
+
elif label == "POSITIVE":
|
22 |
+
suggestions.append("Great! Keep the positivity going with a walk or some light exercise.")
|
23 |
+
else:
|
24 |
+
suggestions.append("Consider focusing on better sleep or reflecting on your priorities.")
|
25 |
+
|
26 |
+
return suggestions
|
27 |
+
|
28 |
+
# Streamlit App
|
29 |
+
st.title("Personalized Self-Care Strategy App")
|
30 |
+
st.markdown("### Answer the following questions to get personalized self-care suggestions.")
|
31 |
+
|
32 |
+
# List of questions
|
33 |
+
questions = [
|
34 |
+
"1. How do you feel about your overall health today?",
|
35 |
+
"2. How have you been sleeping recently?",
|
36 |
+
"3. Do you feel overwhelmed with tasks or emotions?",
|
37 |
+
"4. What are your energy levels like today?",
|
38 |
+
"5. How often do you exercise or engage in physical activity?"
|
39 |
+
]
|
40 |
+
|
41 |
+
# Collect user inputs
|
42 |
+
responses = []
|
43 |
+
for question in questions:
|
44 |
+
responses.append(st.text_input(question, placeholder="Type your response here..."))
|
45 |
+
|
46 |
+
# Button to analyze and provide suggestions
|
47 |
+
if st.button("Get Self-Care Suggestions"):
|
48 |
+
if all(responses): # Ensure all questions are answered
|
49 |
+
suggestions = analyze_and_suggest(responses)
|
50 |
+
st.markdown("### **Your Personalized Suggestions**")
|
51 |
+
for i, suggestion in enumerate(suggestions, 1):
|
52 |
+
st.write(f"**{i}.** {suggestion}")
|
53 |
+
else:
|
54 |
+
st.error("Please answer all the questions before proceeding.")
|