rairo commited on
Commit
705db9f
·
verified ·
1 Parent(s): c764e29

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -14
main.py CHANGED
@@ -1,11 +1,12 @@
1
  """
2
- main.py — Pricelyst Shopping Advisor (Jessica Edition 2026 - Upgrade v2.2)
3
 
4
- ✅ Fixed: Vision SDK Crash (Part.from_text removed)
5
- ✅ Fixed: "Clingy" Memory (Topic Reset Rule added)
6
- "Analyst Engine": Enhanced Basket Math, Category Context, ZESA Logic
7
- ✅ "Visual Engine": Lists, Products, & Meal-to-Recipe recognition
8
- Memory Logic: Short-Term Sliding Window (Last 6 messages)
 
9
 
10
  ENV VARS:
11
  - GOOGLE_API_KEY=...
@@ -469,12 +470,11 @@ def gemini_analyze_image(image_b64: str, caption: str = "") -> Dict[str, Any]:
469
  }}
470
  """
471
  try:
472
- # FIX: Remove types.Part.from_text wrapping. Pass string directly.
473
  image_bytes = base64.b64decode(image_b64)
474
  resp = _gemini_client.models.generate_content(
475
  model=GEMINI_MODEL,
476
  contents=[
477
- PROMPT, # Pass text as string directly
478
  types.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
479
  ],
480
  config=types.GenerateContentConfig(response_mime_type="application/json")
@@ -561,7 +561,7 @@ def health():
561
  "ok": True,
562
  "offers_indexed": len(df),
563
  "api_source": PRICE_API_BASE,
564
- "persona": "Jessica v2.2"
565
  })
566
 
567
  @app.post("/chat")
@@ -633,6 +633,7 @@ def chat():
633
  def analyze_image():
634
  """
635
  Handles Image -> List/Product/Meal -> Shopping Data
 
636
  """
637
  body = request.get_json(silent=True) or {}
638
  image_b64 = body.get("image_data") # Base64 string
@@ -654,15 +655,20 @@ def analyze_image():
654
  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!"
655
 
656
  elif items:
657
- # Run the Analyst Engine
658
  analyst_data = calculate_basket_optimization(items)
659
 
660
- # Craft a specific prompt for image results (No history needed here usually)
661
- intent_sim = {"intent": "SHOPPING_BASKET"}
 
 
 
 
662
  response_text = gemini_chat_response(
663
- f"User uploaded image of {img_type}: {vision_result.get('description')}. Items found: {items}",
664
  intent_sim,
665
- analyst_data
 
666
  )
667
 
668
  return jsonify({
 
1
  """
2
+ main.py — Pricelyst Shopping Advisor (Jessica Edition 2026 - Upgrade v2.3)
3
 
4
+ ✅ Fixed: Image Endpoint now auto-resolves prices (Simulated Intent).
5
+ ✅ Fixed: Vision SDK Crash (Part.from_text removed).
6
+ Fixed: "Clingy" Memory (Topic Reset Rule added).
7
+ ✅ "Analyst Engine": Enhanced Basket Math, Category Context, ZESA Logic.
8
+ "Visual Engine": Lists, Products, & Meal-to-Recipe recognition.
9
+ ✅ Memory Logic: Short-Term Sliding Window (Last 6 messages).
10
 
11
  ENV VARS:
12
  - GOOGLE_API_KEY=...
 
470
  }}
471
  """
472
  try:
 
473
  image_bytes = base64.b64decode(image_b64)
474
  resp = _gemini_client.models.generate_content(
475
  model=GEMINI_MODEL,
476
  contents=[
477
+ PROMPT,
478
  types.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
479
  ],
480
  config=types.GenerateContentConfig(response_mime_type="application/json")
 
561
  "ok": True,
562
  "offers_indexed": len(df),
563
  "api_source": PRICE_API_BASE,
564
+ "persona": "Jessica v2.3"
565
  })
566
 
567
  @app.post("/chat")
 
633
  def analyze_image():
634
  """
635
  Handles Image -> List/Product/Meal -> Shopping Data
636
+ AUTO-RESOLVES intent to give prices immediately.
637
  """
638
  body = request.get_json(silent=True) or {}
639
  image_b64 = body.get("image_data") # Base64 string
 
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 immediately
659
  analyst_data = calculate_basket_optimization(items)
660
 
661
+ # 3. SIMULATE INTENT
662
+ # Instead of asking "Do you want to search?", we simulate a user asking "Where is [item] cheapest?"
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="" # No history needed for fresh lookup
672
  )
673
 
674
  return jsonify({