ankit5566 commited on
Commit
75c8f14
Β·
verified Β·
1 Parent(s): c80434d

Updated app

Browse files

Added improvements in suggestions and added spinning loader

Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -192,14 +192,14 @@ def analyze_image_with_image_recognition(image_bytes):
192
  },
193
  "improvements": {
194
  "suggestions": [
195
- "suggestion 1",
196
- "suggestion 2",
197
- ...
198
  ],
199
- "context": "brief explanation of why these improvements are suggested based on the goal"
200
  }
201
  }
202
- Consider the user's goal when suggesting improvements. Provide only the JSON response without any additional text or explanation."""
203
  },
204
  {
205
  "type": "image_url",
@@ -264,17 +264,21 @@ if uploaded_file:
264
 
265
  # First Analysis Button
266
  if not st.session_state.analysis_done and st.button("Analyze Image"):
267
- image_bytes = process_image_for_analysis(image)
268
- st.session_state.image_bytes = image_bytes
269
- st.session_state.base64_image = base64.b64encode(image_bytes).decode("utf-8")
270
-
271
- # Initial analysis
272
- result = analyze_image_with_image_recognition(image_bytes)
273
- message_content = result.choices[0].message.content
274
- st.session_state.initial_result = parse_nutrition_response(message_content)
275
- st.session_state.analysis_done = True
276
- st.rerun()
277
-
 
 
 
 
278
  # Show results and refinement options after initial analysis
279
  if st.session_state.analysis_done:
280
  parsed_result = st.session_state.initial_result
@@ -328,10 +332,11 @@ Provide the nutritional information in the following JSON format only:
328
  }},
329
  "improvements": {{
330
  "suggestions": [
331
- "suggestion 1",
332
- "suggestion 2"
 
333
  ],
334
- "context": "brief explanation of why these improvements are suggested based on the goal"
335
  }}
336
  }}'''
337
 
 
192
  },
193
  "improvements": {
194
  "suggestions": [
195
+ "🌟 Great choice on including [positive aspect]!",
196
+ "πŸ’ͺ Keep up the good work with [healthy element]!",
197
+ "πŸ’‘ Consider adding [suggestion] to boost nutrition"
198
  ],
199
+ "context": "Start with encouraging feedback about the healthy aspects of the meal, then provide constructive suggestions. Use emojis like πŸ₯— for healthy choices, πŸ’ͺ for protein-rich foods, 🌟 for balanced meals, 🍎 for fruits/vegetables, πŸ’š for nutritious choices."
200
  }
201
  }
202
+ Consider the user's goal when suggesting improvements. Be encouraging when healthy choices are present. Provide only the JSON response without any additional text or explanation."""
203
  },
204
  {
205
  "type": "image_url",
 
264
 
265
  # First Analysis Button
266
  if not st.session_state.analysis_done and st.button("Analyze Image"):
267
+ with st.spinner("πŸ”„ Analyzing your food image... This may take a few seconds."):
268
+ try:
269
+ image_bytes = process_image_for_analysis(image)
270
+ st.session_state.image_bytes = image_bytes
271
+ st.session_state.base64_image = base64.b64encode(image_bytes).decode("utf-8")
272
+
273
+ # Initial analysis
274
+ result = analyze_image_with_image_recognition(image_bytes)
275
+ message_content = result.choices[0].message.content
276
+ st.session_state.initial_result = parse_nutrition_response(message_content)
277
+ st.session_state.analysis_done = True
278
+ st.success("βœ… Analysis completed successfully!")
279
+ st.rerun()
280
+ except Exception as e:
281
+ st.error(f"❌ Error during analysis: {str(e)}")
282
  # Show results and refinement options after initial analysis
283
  if st.session_state.analysis_done:
284
  parsed_result = st.session_state.initial_result
 
332
  }},
333
  "improvements": {{
334
  "suggestions": [
335
+ "🌟 Great choice on including [positive aspect]!",
336
+ "πŸ’ͺ Keep up the good work with [healthy element]!",
337
+ "πŸ’‘ Consider adding [suggestion] to boost nutrition"
338
  ],
339
+ "context": "Start with encouraging feedback about the healthy aspects of the meal, then provide constructive suggestions. Use emojis like πŸ₯— for healthy choices, πŸ’ͺ for protein-rich foods, 🌟 for balanced meals, 🍎 for fruits/vegetables, πŸ’š for nutritious choices."
340
  }}
341
  }}'''
342