Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,46 +11,6 @@ from ultralytics import YOLO
|
|
11 |
|
12 |
model = YOLO("yolov8n.pt") # Nano model for speed, fine-tune on food data later
|
13 |
|
14 |
-
# Multi-label recognition model (placeholder - swap for fine-tuned multi-label later)
|
15 |
-
recognizer = pipeline("image-classification", model=model)
|
16 |
-
|
17 |
-
# AutoGen Agent Definitions
|
18 |
-
food_recognizer = AssistantAgent(
|
19 |
-
name="FoodRecognizer",
|
20 |
-
system_message="Identify all food items in the image and return a list of (label, probability) pairs.",
|
21 |
-
function_map={"recognize_foods": recognize_foods}
|
22 |
-
)
|
23 |
-
|
24 |
-
size_estimator = AssistantAgent(
|
25 |
-
name="SizeEstimator",
|
26 |
-
system_message="Estimate portion sizes in grams for each recognized food based on the image.",
|
27 |
-
function_map={"estimate_sizes": estimate_sizes}
|
28 |
-
)
|
29 |
-
|
30 |
-
nutrition_fetcher = AssistantAgent(
|
31 |
-
name="NutritionFetcher",
|
32 |
-
system_message="Fetch nutritional data from the Nutritionix API using the user's key.",
|
33 |
-
function_map={"fetch_nutrition": fetch_nutrition}
|
34 |
-
)
|
35 |
-
|
36 |
-
##advice_agent = AssistantAgent(
|
37 |
-
## name="NutritionAdvisor",
|
38 |
-
## system_message="Provide basic nutrition advice using the user's OpenAI/Grok key."
|
39 |
-
##)
|
40 |
-
|
41 |
-
orchestrator = AssistantAgent(
|
42 |
-
name="Orchestrator",
|
43 |
-
system_message="Coordinate the workflow, format the output, and return the final result as text.",
|
44 |
-
function_map={}
|
45 |
-
)
|
46 |
-
|
47 |
-
group_chat = GroupChat(
|
48 |
-
agents=[food_recognizer, size_estimator, nutrition_fetcher, advice_agent, orchestrator],
|
49 |
-
messages=[],
|
50 |
-
max_round=10
|
51 |
-
)
|
52 |
-
manager = GroupChatManager(groupchat=group_chat)
|
53 |
-
|
54 |
# Agent Functions
|
55 |
def recognize_foods(image):
|
56 |
start = time.time()
|
@@ -135,6 +95,45 @@ def fetch_nutrition(foods_with_sizes, nutritionix_key):
|
|
135 |
# except Exception as e:
|
136 |
# return f"Error with LLM key: {str(e)}"
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
# Orchestrator Logic (via AutoGen chat)
|
139 |
def orchestrate_workflow(image, nutritionix_key):
|
140 |
start = time.time()
|
|
|
11 |
|
12 |
model = YOLO("yolov8n.pt") # Nano model for speed, fine-tune on food data later
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Agent Functions
|
15 |
def recognize_foods(image):
|
16 |
start = time.time()
|
|
|
95 |
# except Exception as e:
|
96 |
# return f"Error with LLM key: {str(e)}"
|
97 |
|
98 |
+
|
99 |
+
# AutoGen Agent Definitions
|
100 |
+
food_recognizer = AssistantAgent(
|
101 |
+
name="FoodRecognizer",
|
102 |
+
system_message="Identify all food items in the image and return a list of (label, probability) pairs.",
|
103 |
+
function_map={"recognize_foods": recognize_foods}
|
104 |
+
)
|
105 |
+
|
106 |
+
size_estimator = AssistantAgent(
|
107 |
+
name="SizeEstimator",
|
108 |
+
system_message="Estimate portion sizes in grams for each recognized food based on the image.",
|
109 |
+
function_map={"estimate_sizes": estimate_sizes}
|
110 |
+
)
|
111 |
+
|
112 |
+
nutrition_fetcher = AssistantAgent(
|
113 |
+
name="NutritionFetcher",
|
114 |
+
system_message="Fetch nutritional data from the Nutritionix API using the user's key.",
|
115 |
+
function_map={"fetch_nutrition": fetch_nutrition}
|
116 |
+
)
|
117 |
+
|
118 |
+
##advice_agent = AssistantAgent(
|
119 |
+
## name="NutritionAdvisor",
|
120 |
+
## system_message="Provide basic nutrition advice using the user's OpenAI/Grok key."
|
121 |
+
##)
|
122 |
+
|
123 |
+
orchestrator = AssistantAgent(
|
124 |
+
name="Orchestrator",
|
125 |
+
system_message="Coordinate the workflow, format the output, and return the final result as text.",
|
126 |
+
function_map={}
|
127 |
+
)
|
128 |
+
|
129 |
+
group_chat = GroupChat(
|
130 |
+
agents=[food_recognizer, size_estimator, nutrition_fetcher, advice_agent, orchestrator],
|
131 |
+
messages=[],
|
132 |
+
max_round=10
|
133 |
+
)
|
134 |
+
manager = GroupChatManager(groupchat=group_chat)
|
135 |
+
|
136 |
+
|
137 |
# Orchestrator Logic (via AutoGen chat)
|
138 |
def orchestrate_workflow(image, nutritionix_key):
|
139 |
start = time.time()
|