tarrasyed19472007 commited on
Commit
596e12a
Β·
verified Β·
1 Parent(s): 24cf228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -60
app.py CHANGED
@@ -1,64 +1,35 @@
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
- )
 
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}")