Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -633,10 +633,10 @@ def chat():
|
|
| 633 |
def analyze_image():
|
| 634 |
"""
|
| 635 |
Handles Image -> List/Product/Meal -> Shopping Data
|
| 636 |
-
AUTO-RESOLVES intent
|
| 637 |
"""
|
| 638 |
body = request.get_json(silent=True) or {}
|
| 639 |
-
image_b64 = body.get("image_data")
|
| 640 |
caption = body.get("caption", "")
|
| 641 |
pid = body.get("profile_id")
|
| 642 |
|
|
@@ -646,6 +646,7 @@ def analyze_image():
|
|
| 646 |
vision_result = gemini_analyze_image(image_b64, caption)
|
| 647 |
img_type = vision_result.get("type", "IRRELEVANT")
|
| 648 |
items = vision_result.get("items", [])
|
|
|
|
| 649 |
|
| 650 |
response_text = ""
|
| 651 |
analyst_data = {}
|
|
@@ -655,20 +656,33 @@ def analyze_image():
|
|
| 655 |
response_text = "I see the image, but I can't find any shopping items or meals in it. Try a receipt, a product, or a plate of food!"
|
| 656 |
|
| 657 |
elif items:
|
| 658 |
-
# Run the Analyst Engine
|
| 659 |
analyst_data = calculate_basket_optimization(items)
|
| 660 |
|
| 661 |
-
# 3.
|
| 662 |
-
#
|
| 663 |
-
# This forces the Persona to look at the analyst_data and reply with the solution.
|
| 664 |
-
simulated_user_msg = f"I have a photo of {', '.join(items)}. Which store has the cheapest price for this right now?"
|
| 665 |
-
intent_sim = {"intent": "STORE_DECISION"}
|
| 666 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
response_text = gemini_chat_response(
|
| 668 |
simulated_user_msg,
|
| 669 |
intent_sim,
|
| 670 |
analyst_data,
|
| 671 |
-
chat_history="" #
|
| 672 |
)
|
| 673 |
|
| 674 |
return jsonify({
|
|
|
|
| 633 |
def analyze_image():
|
| 634 |
"""
|
| 635 |
Handles Image -> List/Product/Meal -> Shopping Data
|
| 636 |
+
AUTO-RESOLVES intent with Context-Aware Simulation.
|
| 637 |
"""
|
| 638 |
body = request.get_json(silent=True) or {}
|
| 639 |
+
image_b64 = body.get("image_data")
|
| 640 |
caption = body.get("caption", "")
|
| 641 |
pid = body.get("profile_id")
|
| 642 |
|
|
|
|
| 646 |
vision_result = gemini_analyze_image(image_b64, caption)
|
| 647 |
img_type = vision_result.get("type", "IRRELEVANT")
|
| 648 |
items = vision_result.get("items", [])
|
| 649 |
+
description = vision_result.get("description", "item")
|
| 650 |
|
| 651 |
response_text = ""
|
| 652 |
analyst_data = {}
|
|
|
|
| 656 |
response_text = "I see the image, but I can't find any shopping items or meals in it. Try a receipt, a product, or a plate of food!"
|
| 657 |
|
| 658 |
elif items:
|
| 659 |
+
# Run the Analyst Engine
|
| 660 |
analyst_data = calculate_basket_optimization(items)
|
| 661 |
|
| 662 |
+
# 3. DYNAMIC SIMULATED INTENT
|
| 663 |
+
# We vary the "user voice" so Jessica's reply matches the context.
|
|
|
|
|
|
|
|
|
|
| 664 |
|
| 665 |
+
if img_type == "MEAL":
|
| 666 |
+
# Context: "I want to cook this"
|
| 667 |
+
simulated_user_msg = f"I want to cook {description}. I need these ingredients: {', '.join(items)}. How much will it cost to make this?"
|
| 668 |
+
intent_sim = {"intent": "SHOPPING_BASKET"} # Triggers advice mode
|
| 669 |
+
|
| 670 |
+
elif img_type == "LIST":
|
| 671 |
+
# Context: "Quote this list"
|
| 672 |
+
simulated_user_msg = f"Here is my shopping list: {', '.join(items)}. Which store is cheapest for the whole basket?"
|
| 673 |
+
intent_sim = {"intent": "STORE_DECISION"}
|
| 674 |
+
|
| 675 |
+
else: # PRODUCT
|
| 676 |
+
# Context: "Price check"
|
| 677 |
+
simulated_user_msg = f"I see {description}. Which store has the cheapest price for it right now?"
|
| 678 |
+
intent_sim = {"intent": "STORE_DECISION"}
|
| 679 |
+
|
| 680 |
+
# Generate Response
|
| 681 |
response_text = gemini_chat_response(
|
| 682 |
simulated_user_msg,
|
| 683 |
intent_sim,
|
| 684 |
analyst_data,
|
| 685 |
+
chat_history="" # Fresh context
|
| 686 |
)
|
| 687 |
|
| 688 |
return jsonify({
|