ibrahim yıldız commited on
Commit
289182b
·
verified ·
1 Parent(s): 7b74593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -36
app.py CHANGED
@@ -179,44 +179,48 @@ if all(st.session_state.meal_data[meal] for meal in ["Breakfast", "Lunch", "Dinn
179
  )
180
 
181
  if st.button("Analyze Workout"):
182
- with st.spinner("Analyzing your workout..."):
183
- try:
184
- # Gemini prompt for workout analysis
185
- workout_prompt = f"""
186
- You are an expert fitness tracker. The user did the following activities today:
187
- {workout_input}
188
- Calculate the total calories burned based on the description.
189
- Provide data in this format: "X calories burned by [activity descriptions]." Say nothing else.
190
- """
191
- # Analyze workout using Gemini for text
192
- model = genai.GenerativeModel("gemini-1.5-pro-latest")
193
- workout_analysis = model.generate_content([workout_prompt]).text.strip()
194
- st.session_state.daily_totals["Workout"] = workout_analysis
 
 
 
195
 
196
- # Dobby's feedback on the workout
197
- dobby_workout_prompt = f"""
198
- The user performed the following workout activities: {workout_input}.
199
- Based on the analysis, {workout_analysis}.
200
- Provide sarcastic or motivational feedback based on the user's goal to {st.session_state.user_info["Goal"].lower()}.
201
- """
202
- dobby_workout_comment = requests.post(
203
- DOBBY_API_URL,
204
- headers={
205
- "Authorization": f"Bearer {DOBBY_API_KEY}",
206
- "Content-Type": "application/json",
207
- },
208
- json={
209
- "model": DOBBY_UNHINGED_MODEL, # Default to unhinged tone
210
- "messages": [{"role": "user", "content": dobby_workout_prompt}],
211
- },
212
- ).json().get("choices", [{}])[0].get("message", {}).get("content", "No response")
213
- st.session_state.daily_totals["Workout Comment"] = dobby_workout_comment
214
 
215
- # Display workout results
216
- st.write(f"**{workout_analysis}**")
217
- st.write({dobby_workout_comment}")
218
- except Exception as e:
219
- st.error(f"Error processing workout: {e}")
 
220
 
221
  # Step 4: Daily Summary
222
  if "Workout" in st.session_state.daily_totals:
 
179
  )
180
 
181
  if st.button("Analyze Workout"):
182
+ if workout_input.strip() == "":
183
+ st.error("Please describe your workout before analyzing!")
184
+ else:
185
+ with st.spinner("Analyzing your workout..."):
186
+ try:
187
+ # Gemini prompt for workout analysis
188
+ workout_prompt = f"""
189
+ You are an expert fitness tracker. The user did the following activities today:
190
+ {workout_input}
191
+ Calculate the total calories burned based on the description.
192
+ Provide data in this format: "X calories burned by [activity descriptions]." Say nothing else.
193
+ """
194
+ # Analyze workout using Gemini for text
195
+ model = genai.GenerativeModel("gemini-1.5-pro-latest")
196
+ workout_analysis = model.generate_content([workout_prompt]).text.strip()
197
+ st.session_state.daily_totals["Workout"] = workout_analysis
198
 
199
+ # Dobby's feedback on the workout
200
+ dobby_workout_prompt = f"""
201
+ The user performed the following workout activities: {workout_input}.
202
+ Based on the analysis, {workout_analysis}.
203
+ Provide sarcastic or motivational feedback based on the user's goal to {st.session_state.user_info["Goal"].lower()}.
204
+ """
205
+ dobby_workout_comment = requests.post(
206
+ DOBBY_API_URL,
207
+ headers={
208
+ "Authorization": f"Bearer {DOBBY_API_KEY}",
209
+ "Content-Type": "application/json",
210
+ },
211
+ json={
212
+ "model": DOBBY_UNHINGED_MODEL, # Default to unhinged tone
213
+ "messages": [{"role": "user", "content": dobby_workout_prompt}],
214
+ },
215
+ ).json().get("choices", [{}])[0].get("message", {}).get("content", "No response")
216
+ st.session_state.daily_totals["Workout Comment"] = dobby_workout_comment
217
 
218
+ # Display workout results
219
+ st.write(f"**{workout_analysis}**")
220
+ st.write(dobby_workout_comment)
221
+ except Exception as e:
222
+ st.error(f"Error processing workout: {e}")
223
+
224
 
225
  # Step 4: Daily Summary
226
  if "Workout" in st.session_state.daily_totals: