Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,35 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the emotion
|
5 |
-
emotion_analyzer = pipeline(
|
6 |
-
|
7 |
-
|
8 |
-
)
|
9 |
-
|
10 |
-
#
|
11 |
-
st.
|
12 |
-
|
13 |
-
st.
|
14 |
-
|
15 |
-
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
if
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
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 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
st.
|
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 |
-
)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the emotion classification model
|
5 |
+
emotion_analyzer = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment")
|
6 |
+
|
7 |
+
# Streamlit app interface
|
8 |
+
st.title("Emotion Prediction and Well-Being Suggestions")
|
9 |
+
|
10 |
+
# Ask 3 questions to the user
|
11 |
+
question1 = st.text_input("How are you feeling today?")
|
12 |
+
question2 = st.text_input("Have you felt stressed recently?")
|
13 |
+
question3 = st.text_input("Do you have enough time for relaxation?")
|
14 |
+
|
15 |
+
if st.button("Get Suggestions"):
|
16 |
+
# Combine responses to analyze sentiment
|
17 |
+
user_input = f"{question1} {question2} {question3}"
|
18 |
+
|
19 |
+
# Perform emotion analysis
|
20 |
+
emotion = emotion_analyzer(user_input)
|
21 |
+
|
22 |
+
# Provide suggestions based on emotion
|
23 |
+
if "positive" in emotion[0]['label'].lower():
|
24 |
+
suggestion = "It's great to hear that you're feeling positive! Consider doing a relaxing activity like walking on the beach or practicing mindfulness."
|
25 |
+
video_url = "https://www.youtube.com/watch?v=1LkV2STw2so" # Example relaxation video
|
26 |
+
elif "negative" in emotion[0]['label'].lower():
|
27 |
+
suggestion = "It seems like you're experiencing some stress. Try deep breathing exercises or a walk in nature to relieve tension."
|
28 |
+
video_url = "https://www.youtube.com/watch?v=5J5nZ9Tr6Cw" # Example deep breathing exercise video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
else:
|
30 |
+
suggestion = "It seems like you're having a mixed experience. Balance your day with some light exercise like hula dancing or yoga."
|
31 |
+
video_url = "https://www.youtube.com/watch?v=Hk4pJOPsFq4" # Example hula dancing video
|
32 |
+
|
33 |
+
# Show suggestions and video
|
34 |
+
st.write(suggestion)
|
35 |
+
st.write(f"Check out this video for more guidance: {video_url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|