Spaces:
Sleeping
Sleeping
ibrahim yıldız commited on
Update app.py
Browse files
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 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 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:
|