tarrasyed19472007 commited on
Commit
2fbc1cc
Β·
verified Β·
1 Parent(s): aac8809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -88
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 an open-access model
5
  emotion_analyzer = pipeline(
6
  "text-classification",
7
  model="j-hartmann/emotion-english-distilroberta-base"
8
  )
9
 
10
- # App title and description
11
- st.set_page_config(page_title="Hawaii Emotion Wellness", layout="centered", page_icon="🌴")
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
- # Analyze the emotions if the user has answered all questions
58
- if st.button("Analyze Emotions"):
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
- # Get the most likely emotion
65
- predicted_emotion = emotion_results[0]["label"]
66
- st.markdown(f"### Your Predicted Emotion: **{predicted_emotion}** 🎭")
 
 
67
 
68
- # Provide well-being suggestions
69
- st.markdown("### Here's what we recommend for you:")
70
- suggestions = {
71
- "joy": [
72
- {"activity": "Go for a walk on the beach", "url": "https://www.hawaiibeachwalks.com"},
73
- {"activity": "Try a short surfing session", "url": "https://www.learnsurf.com"},
74
- {"activity": "Join a hula dancing class", "url": "https://www.hulahawaii.com"},
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
- user_suggestions = suggestions.get(predicted_emotion.lower(), [])
85
- if user_suggestions:
86
- for suggestion in user_suggestions:
87
- st.markdown(
88
- f"""
89
- <div class="suggestion-card">
90
- <strong>{suggestion['activity']}</strong>
91
- <br>
92
- <a href="{suggestion['url']}" target="_blank">Learn More</a>
93
- </div>
94
- """,
95
- unsafe_allow_html=True,
96
- )
97
  else:
98
- st.markdown("Stay positive! Enjoy the aloha spirit and take a deep breath.")
 
99
  else:
100
- st.warning("Please answer all the questions to analyze your emotions.")
101
 
102
  # Footer
103
  st.markdown("---")
 
 
 
104
  st.markdown(
105
- "Built with ❀️ for the Hawaii Hackathon 2024 by [Your Team Name]. Deployed on Hugging Face Spaces."
 
 
 
 
 
 
 
 
 
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
  )