tdurzynski commited on
Commit
2a1c9dd
·
verified ·
1 Parent(s): f161f5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -7,7 +7,7 @@ import requests
7
  import os
8
  import time
9
  from autogen import AssistantAgent, GroupChat, GroupChatManager
10
- import openai
11
 
12
  # Initialize YOLOv8 for multi-label food detection
13
  model = YOLO("yolov8n.pt") # Nano model for speed, fine-tune on food data later
@@ -34,12 +34,12 @@ def recognize_foods(image):
34
  for result in results:
35
  for cls in result.boxes.cls:
36
  label = model.names[int(cls)]
37
- if "food" in label.lower() or label in ["pasta", "rice", "tomato", "potato", "bread", "curry"]: # Expand this list
38
  conf = result.boxes.conf[result.boxes.cls == cls].item()
39
  foods.append((label, conf))
40
  detected = True
41
  if not detected:
42
- print("Warning: No food items detected in the image.")
43
  print(f"Recognition took {time.time() - start:.2f}s: Found foods {foods}")
44
  return list(set(foods)) # Remove duplicates
45
 
@@ -157,25 +157,25 @@ def get_nutrition_advice(nutrition_data, openai_key):
157
  # AutoGen Agent Definitions
158
  food_recognizer = AssistantAgent(
159
  name="FoodRecognizer",
160
- system_message="Identify all food items in the image and return a list of (label, probability) pairs. Call recognize_foods with the image provided in the message.",
161
  function_map={"recognize_foods": recognize_foods}
162
  )
163
 
164
  size_estimator = AssistantAgent(
165
  name="SizeEstimator",
166
- system_message="Estimate portion sizes in grams for each recognized food based on the image. Call estimate_sizes with the image and list of foods from the previous message.",
167
  function_map={"estimate_sizes": estimate_sizes}
168
  )
169
 
170
  nutrition_fetcher = AssistantAgent(
171
  name="NutritionFetcher",
172
- system_message="Fetch nutritional data from the Nutritionix API using the user's key. Call fetch_nutrition with the foods and sizes dictionary from the previous message and the Nutritionix key from the initial message.",
173
  function_map={"fetch_nutrition": fetch_nutrition}
174
  )
175
 
176
  advice_agent = AssistantAgent(
177
  name="NutritionAdvisor",
178
- system_message="Provide basic nutrition advice based on the food data using the user's OpenAI key. Call get_nutrition_advice with the nutrition data from the previous message and the OpenAI key from the initial message.",
179
  function_map={"get_nutrition_advice": get_nutrition_advice}
180
  )
181
 
 
7
  import os
8
  import time
9
  from autogen import AssistantAgent, GroupChat, GroupChatManager
10
+ import openai
11
 
12
  # Initialize YOLOv8 for multi-label food detection
13
  model = YOLO("yolov8n.pt") # Nano model for speed, fine-tune on food data later
 
34
  for result in results:
35
  for cls in result.boxes.cls:
36
  label = model.names[int(cls)]
37
+ if "food" in label.lower() or label in ["broccoli", "carrot", "green bean", "chicken", "turkey", "pasta", "rice", "tomato", "potato", "bread", "curry"]: # Expanded list
38
  conf = result.boxes.conf[result.boxes.cls == cls].item()
39
  foods.append((label, conf))
40
  detected = True
41
  if not detected:
42
+ print("Warning: No food items detected in the image. Check YOLOv8 model or image quality.")
43
  print(f"Recognition took {time.time() - start:.2f}s: Found foods {foods}")
44
  return list(set(foods)) # Remove duplicates
45
 
 
157
  # AutoGen Agent Definitions
158
  food_recognizer = AssistantAgent(
159
  name="FoodRecognizer",
160
+ system_message="Identify all food items in the image and return a list of (label, probability) pairs. Parse the message for the image data and call recognize_foods with it.",
161
  function_map={"recognize_foods": recognize_foods}
162
  )
163
 
164
  size_estimator = AssistantAgent(
165
  name="SizeEstimator",
166
+ system_message="Estimate portion sizes in grams for each recognized food based on the image. Parse the previous message for the list of foods and call estimate_sizes with the image and foods.",
167
  function_map={"estimate_sizes": estimate_sizes}
168
  )
169
 
170
  nutrition_fetcher = AssistantAgent(
171
  name="NutritionFetcher",
172
+ system_message="Fetch nutritional data from the Nutritionix API using the user's key. Parse the previous message for the foods and sizes dictionary and the initial message for the Nutritionix key, then call fetch_nutrition.",
173
  function_map={"fetch_nutrition": fetch_nutrition}
174
  )
175
 
176
  advice_agent = AssistantAgent(
177
  name="NutritionAdvisor",
178
+ system_message="Provide basic nutrition advice based on the food data using the user's OpenAI key. Parse the previous message for the nutrition data and the initial message for the OpenAI key, then call get_nutrition_advice.",
179
  function_map={"get_nutrition_advice": get_nutrition_advice}
180
  )
181