Spaces:
Running
Running
Updated app
Browse filesAdded improvements in suggestions and added spinning loader
app.py
CHANGED
|
@@ -192,14 +192,14 @@ def analyze_image_with_image_recognition(image_bytes):
|
|
| 192 |
},
|
| 193 |
"improvements": {
|
| 194 |
"suggestions": [
|
| 195 |
-
"
|
| 196 |
-
"
|
| 197 |
-
|
| 198 |
],
|
| 199 |
-
"context": "
|
| 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 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 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 |
-
"
|
| 332 |
-
"
|
|
|
|
| 333 |
],
|
| 334 |
-
"context": "
|
| 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 |
|