Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,107 +1,64 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the emotion analysis pipeline using
|
5 |
emotion_analyzer = pipeline(
|
6 |
"text-classification",
|
7 |
model="j-hartmann/emotion-english-distilroberta-base"
|
8 |
)
|
9 |
|
10 |
-
#
|
11 |
-
st.set_page_config(page_title="
|
12 |
-
st.markdown(
|
13 |
-
"""
|
14 |
-
<style>
|
15 |
-
body {
|
16 |
-
background-color: #E0F7FA;
|
17 |
-
color: #004D40;
|
18 |
-
}
|
19 |
-
.main-header {
|
20 |
-
font-size: 36px;
|
21 |
-
font-weight: bold;
|
22 |
-
text-align: center;
|
23 |
-
margin-bottom: 10px;
|
24 |
-
}
|
25 |
-
.sub-header {
|
26 |
-
font-size: 18px;
|
27 |
-
text-align: center;
|
28 |
-
margin-bottom: 20px;
|
29 |
-
}
|
30 |
-
.suggestion-card {
|
31 |
-
background-color: #B2EBF2;
|
32 |
-
padding: 15px;
|
33 |
-
border-radius: 8px;
|
34 |
-
margin-bottom: 15px;
|
35 |
-
}
|
36 |
-
</style>
|
37 |
-
""",
|
38 |
-
unsafe_allow_html=True,
|
39 |
-
)
|
40 |
-
|
41 |
-
st.markdown('<div class="main-header">πΊ Hawaii Emotion Wellness App π΄</div>', unsafe_allow_html=True)
|
42 |
-
st.markdown('<div class="sub-header">Understand your emotions and find the right balance in paradise.</div>', unsafe_allow_html=True)
|
43 |
-
|
44 |
-
# Step 1: Collect user's responses
|
45 |
-
st.markdown("### Answer these three questions to get started:")
|
46 |
-
questions = [
|
47 |
-
"How are you feeling right now? (e.g., stressed, happy, sad)",
|
48 |
-
"What is the most pressing issue on your mind currently?",
|
49 |
-
"On a scale of 1-10, how motivated do you feel to take care of yourself today?",
|
50 |
-
]
|
51 |
-
|
52 |
-
responses = []
|
53 |
-
for question in questions:
|
54 |
-
response = st.text_input(question)
|
55 |
-
responses.append(response)
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
if all(responses):
|
60 |
-
# Aggregate responses into a single input for emotion analysis
|
61 |
-
aggregated_response = " ".join(responses)
|
62 |
-
emotion_results = emotion_analyzer(aggregated_response)
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
"sadness": [
|
77 |
-
{"activity": "Practice deep breathing for 5 minutes", "url": "https://www.breathingexercise.com"},
|
78 |
-
{"activity": "Watch a calming ocean video", "url": "https://www.youtube.com/watch?v=lM02vNMRRB0"},
|
79 |
-
{"activity": "Do a quick yoga session", "url": "https://www.doyogawithme.com"},
|
80 |
-
],
|
81 |
-
# Add more emotions as needed
|
82 |
-
}
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
unsafe_allow_html=True,
|
96 |
-
)
|
97 |
else:
|
98 |
-
st.markdown("Stay positive
|
|
|
99 |
else:
|
100 |
-
st.
|
101 |
|
102 |
# Footer
|
103 |
st.markdown("---")
|
|
|
|
|
|
|
104 |
st.markdown(
|
105 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
)
|
107 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the emotion analysis pipeline using a publicly available fine-tuned model
|
5 |
emotion_analyzer = pipeline(
|
6 |
"text-classification",
|
7 |
model="j-hartmann/emotion-english-distilroberta-base"
|
8 |
)
|
9 |
|
10 |
+
# Streamlit app setup
|
11 |
+
st.set_page_config(page_title="Emotion Wellness App", page_icon="πΊ", layout="centered")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
st.title("Emotion Wellness Predictor πΊ")
|
14 |
+
st.subheader("Discover your emotions and find ways to enhance your well-being.")
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Questions for the user
|
17 |
+
st.markdown("### Answer the following questions:")
|
18 |
+
q1 = st.text_input("How are you feeling today? (e.g., happy, sad, stressed)")
|
19 |
+
q2 = st.text_input("Whatβs currently on your mind?")
|
20 |
+
q3 = st.slider("On a scale of 1-10, how motivated do you feel?", 1, 10)
|
21 |
|
22 |
+
# Analyze emotions when the button is pressed
|
23 |
+
if st.button("Analyze My Emotions"):
|
24 |
+
if q1 and q2:
|
25 |
+
# Combine user inputs into a single string for emotion analysis
|
26 |
+
user_input = f"{q1} {q2}"
|
27 |
+
results = emotion_analyzer(user_input)
|
28 |
+
predicted_emotion = results[0]['label']
|
29 |
+
st.markdown(f"### Detected Emotion: **{predicted_emotion}** π")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
# Suggestions based on emotion
|
32 |
+
st.markdown("### Suggested Activities:")
|
33 |
+
if predicted_emotion == "joy":
|
34 |
+
st.markdown("- π Take a walk on the beach\n- π§ββοΈ Try a yoga session\n- π΅ Listen to upbeat music")
|
35 |
+
st.markdown("[Explore mindfulness exercises](https://www.mindfulness.org)")
|
36 |
+
elif predicted_emotion == "sadness":
|
37 |
+
st.markdown("- πΌ Practice gratitude journaling\n- π§ββοΈ Meditate for 10 minutes\n- π Read something uplifting")
|
38 |
+
st.markdown("[Watch a calming video](https://www.youtube.com/watch?v=ZQ6aGy7tjTc)")
|
39 |
+
elif predicted_emotion == "anger":
|
40 |
+
st.markdown("- πββοΈ Go for a run\n- πΏ Spend time in nature\n- π¬ Talk to a friend")
|
41 |
+
st.markdown("[Explore anger management tips](https://www.mentalhealth.org.uk)")
|
|
|
|
|
42 |
else:
|
43 |
+
st.markdown("- π‘ Stay positive and focus on your goals.")
|
44 |
+
|
45 |
else:
|
46 |
+
st.error("Please answer all questions to analyze your emotions.")
|
47 |
|
48 |
# Footer
|
49 |
st.markdown("---")
|
50 |
+
st.markdown("Built with β€οΈ for the Hawaii Hackathon 2024 by [Your Team Name].")
|
51 |
+
|
52 |
+
# Deployment Instructions
|
53 |
st.markdown(
|
54 |
+
"""
|
55 |
+
To deploy this app:
|
56 |
+
1. Save this script as `app.py`.
|
57 |
+
2. Create a `requirements.txt` file:
|
58 |
+
```
|
59 |
+
streamlit
|
60 |
+
transformers
|
61 |
+
```
|
62 |
+
3. Deploy on Hugging Face Spaces or Streamlit Sharing.
|
63 |
+
"""
|
64 |
)
|
|