Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -104,24 +104,34 @@ if 'previous_responses' not in st.session_state:
|
|
104 |
if 'badges' not in st.session_state:
|
105 |
st.session_state.badges = []
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
if user_input:
|
108 |
-
with st.spinner("
|
|
|
|
|
|
|
|
|
109 |
response = generate_response(user_input)
|
|
|
|
|
|
|
110 |
|
111 |
-
#
|
112 |
-
st.text_area("Bot's Response:", response, height=250)
|
113 |
-
|
114 |
-
|
115 |
-
# Assign motivational badges
|
116 |
if emotion in ["joy", "optimism"]:
|
117 |
badge = "π Positivity Badge"
|
118 |
if badge not in st.session_state.badges:
|
119 |
st.session_state.badges.append(badge)
|
120 |
st.success(f"Congratulations! You've earned a {badge}!")
|
121 |
-
|
122 |
-
# Suggest activities
|
123 |
st.info("π¨ Try a New Activity")
|
124 |
-
activities = ["exercise", "yoga", "journaling", "painting", "meditation", "
|
125 |
selected_activity = st.selectbox("Pick an activity:", activities)
|
126 |
|
127 |
if st.button("Find Videos"):
|
@@ -133,10 +143,11 @@ if user_input:
|
|
133 |
st.write(f"No results found for '{selected_activity}'.")
|
134 |
|
135 |
# Crisis resources
|
136 |
-
if any(word in user_input.lower() for word in ["suicide", "help", "depressed"]):
|
137 |
st.warning("Please reach out to a crisis hotline for immediate support.")
|
138 |
st.write("[Find emergency resources here](https://www.helpguide.org/find-help.htm)")
|
139 |
|
|
|
140 |
# Generate audio response
|
141 |
if user_input:
|
142 |
tts = gTTS(response, lang='en')
|
|
|
104 |
if 'badges' not in st.session_state:
|
105 |
st.session_state.badges = []
|
106 |
|
107 |
+
# User input section
|
108 |
+
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
109 |
+
|
110 |
+
# Initialize session state
|
111 |
+
if 'badges' not in st.session_state:
|
112 |
+
st.session_state.badges = []
|
113 |
+
|
114 |
if user_input:
|
115 |
+
with st.spinner("Analyzing your input..."):
|
116 |
+
# Get the emotion of the user input
|
117 |
+
emotion = get_emotion(user_input)
|
118 |
+
|
119 |
+
# Generate an empathetic response
|
120 |
response = generate_response(user_input)
|
121 |
+
|
122 |
+
# Display the bot's response
|
123 |
+
st.text_area("Bot's Response:", response, height=250)
|
124 |
|
125 |
+
# Assign badges based on the detected emotion
|
|
|
|
|
|
|
|
|
126 |
if emotion in ["joy", "optimism"]:
|
127 |
badge = "π Positivity Badge"
|
128 |
if badge not in st.session_state.badges:
|
129 |
st.session_state.badges.append(badge)
|
130 |
st.success(f"Congratulations! You've earned a {badge}!")
|
131 |
+
|
132 |
+
# Suggest activities based on emotion
|
133 |
st.info("π¨ Try a New Activity")
|
134 |
+
activities = ["exercise", "yoga", "journaling", "painting", "meditation", "swimming"]
|
135 |
selected_activity = st.selectbox("Pick an activity:", activities)
|
136 |
|
137 |
if st.button("Find Videos"):
|
|
|
143 |
st.write(f"No results found for '{selected_activity}'.")
|
144 |
|
145 |
# Crisis resources
|
146 |
+
if user_input and any(word in user_input.lower() for word in ["suicide", "help", "depressed"]):
|
147 |
st.warning("Please reach out to a crisis hotline for immediate support.")
|
148 |
st.write("[Find emergency resources here](https://www.helpguide.org/find-help.htm)")
|
149 |
|
150 |
+
|
151 |
# Generate audio response
|
152 |
if user_input:
|
153 |
tts = gTTS(response, lang='en')
|