tarrasyed19472007 commited on
Commit
defadc6
·
verified ·
1 Parent(s): 6ba3f8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -151,43 +151,47 @@ def main():
151
  user_input = st.text_area("Enter a short sentence about your current mood:", "")
152
 
153
  if user_input:
154
- # Clean the input text (stripping unnecessary spaces, lowercasing)
155
- clean_input = user_input.strip().lower()
156
 
157
- # Use the model to predict emotion
158
- try:
159
- result = emotion_classifier(clean_input)
160
- st.write(f"Raw Model Result: {result}") # Debug output to see raw result
161
 
162
- emotion = result[0]['label'].lower()
163
-
164
- st.subheader(f"Emotion Detected: {emotion.capitalize()}")
165
-
166
- # Get well-being suggestions based on emotion
167
- suggestions = get_well_being_suggestions(emotion)
168
-
169
- # Display text suggestions
170
- st.write(suggestions["text"])
 
 
 
 
 
171
 
172
- # Display links
173
- if suggestions["links"]:
174
- st.write("Useful Resources:")
175
- for link in suggestions["links"]:
176
- st.markdown(f"[{link}]({link})", unsafe_allow_html=True)
177
 
178
- # Display video links
179
- if suggestions["videos"]:
180
- st.write("Relaxation Videos:")
181
- for video in suggestions["videos"]:
182
- st.markdown(f"[Watch here]({video})", unsafe_allow_html=True)
183
 
184
- # Add a button for a summary
185
- if st.button('Summary'):
186
- st.write(f"Emotion detected: {emotion.capitalize()}. Here are your well-being suggestions to enhance your mood.")
187
- st.write("Explore the links and videos to improve your emotional health!")
188
 
189
- except Exception as e:
190
- st.error(f"Error predicting emotion: {str(e)}")
191
 
192
  # Run the Streamlit app
193
  if __name__ == "__main__":
 
151
  user_input = st.text_area("Enter a short sentence about your current mood:", "")
152
 
153
  if user_input:
154
+ # Display Enter button only after user has entered input
155
+ enter_button = st.button("Enter")
156
 
157
+ if enter_button:
158
+ # Clean the input text (stripping unnecessary spaces, lowercasing)
159
+ clean_input = user_input.strip().lower()
 
160
 
161
+ # Use the model to predict emotion
162
+ try:
163
+ result = emotion_classifier(clean_input)
164
+ st.write(f"Raw Model Result: {result}") # Debug output to see raw result
165
+
166
+ emotion = result[0]['label'].lower()
167
+
168
+ st.subheader(f"Emotion Detected: {emotion.capitalize()}")
169
+
170
+ # Get well-being suggestions based on emotion
171
+ suggestions = get_well_being_suggestions(emotion)
172
+
173
+ # Display text suggestions
174
+ st.write(suggestions["text"])
175
 
176
+ # Display links
177
+ if suggestions["links"]:
178
+ st.write("Useful Resources:")
179
+ for link in suggestions["links"]:
180
+ st.markdown(f"[{link}]({link})", unsafe_allow_html=True)
181
 
182
+ # Display video links
183
+ if suggestions["videos"]:
184
+ st.write("Relaxation Videos:")
185
+ for video in suggestions["videos"]:
186
+ st.markdown(f"[Watch here]({video})", unsafe_allow_html=True)
187
 
188
+ # Add a button for a summary
189
+ if st.button('Summary'):
190
+ st.write(f"Emotion detected: {emotion.capitalize()}. Here are your well-being suggestions to enhance your mood.")
191
+ st.write("Explore the links and videos to improve your emotional health!")
192
 
193
+ except Exception as e:
194
+ st.error(f"Error predicting emotion: {str(e)}")
195
 
196
  # Run the Streamlit app
197
  if __name__ == "__main__":