Spaces:
Sleeping
Sleeping
mriusero
commited on
Commit
·
8289a78
1
Parent(s):
e5c9daf
feat: classify foods
Browse files- src/tools/classify_food.py +12 -6
src/tools/classify_food.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
from src.utils.tooling import tool
|
2 |
|
3 |
@tool
|
4 |
-
def classify_foods(food_list: list) ->
|
5 |
"""
|
6 |
Classifies a list of foods into specific botanical categories.
|
7 |
Args:
|
8 |
food_list (list): A list of foods to classify.
|
9 |
Returns:
|
10 |
-
|
11 |
"""
|
12 |
categories = {
|
13 |
"fruits": [
|
@@ -19,7 +19,8 @@ def classify_foods(food_list: list) -> dict:
|
|
19 |
"vegetables": [
|
20 |
"carrot", "broccoli", "spinach", "lettuce", "celery", "fresh basil", "sweet potato",
|
21 |
"potato", "onion", "garlic", "cabbage", "kale", "cauliflower", "asparagus", "radish",
|
22 |
-
"turnip", "beet", "artichoke", "brussels sprouts", "
|
|
|
23 |
],
|
24 |
"grains": [
|
25 |
"rice", "wheat", "oats", "barley", "quinoa", "corn", "rye", "millet", "sorghum",
|
@@ -31,7 +32,7 @@ def classify_foods(food_list: list) -> dict:
|
|
31 |
],
|
32 |
"legumes": [
|
33 |
"lentil", "chickpea", "bean", "pea", "soybean", "black bean", "kidney bean", "pinto bean",
|
34 |
-
"navy bean", "lima bean", "green
|
35 |
],
|
36 |
"other": [
|
37 |
"milk", "eggs", "coffee", "Oreos", "allspice", "sugar", "salt", "honey", "maple syrup",
|
@@ -51,6 +52,11 @@ def classify_foods(food_list: list) -> dict:
|
|
51 |
if not classified:
|
52 |
classified_foods.setdefault("unknown", []).append(food)
|
53 |
|
54 |
-
classified_foods["vegetables"].sort()
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from src.utils.tooling import tool
|
2 |
|
3 |
@tool
|
4 |
+
def classify_foods(food_list: list) -> str:
|
5 |
"""
|
6 |
Classifies a list of foods into specific botanical categories.
|
7 |
Args:
|
8 |
food_list (list): A list of foods to classify.
|
9 |
Returns:
|
10 |
+
str: A string with categories as keys and lists of foods as values.
|
11 |
"""
|
12 |
categories = {
|
13 |
"fruits": [
|
|
|
19 |
"vegetables": [
|
20 |
"carrot", "broccoli", "spinach", "lettuce", "celery", "fresh basil", "sweet potato",
|
21 |
"potato", "onion", "garlic", "cabbage", "kale", "cauliflower", "asparagus", "radish",
|
22 |
+
"turnip", "beet", "artichoke", "brussels sprouts", "peas", "mushroom",
|
23 |
+
"sweet potatoes",
|
24 |
],
|
25 |
"grains": [
|
26 |
"rice", "wheat", "oats", "barley", "quinoa", "corn", "rye", "millet", "sorghum",
|
|
|
32 |
],
|
33 |
"legumes": [
|
34 |
"lentil", "chickpea", "bean", "pea", "soybean", "black bean", "kidney bean", "pinto bean",
|
35 |
+
"navy bean", "lima bean", "green beans",
|
36 |
],
|
37 |
"other": [
|
38 |
"milk", "eggs", "coffee", "Oreos", "allspice", "sugar", "salt", "honey", "maple syrup",
|
|
|
52 |
if not classified:
|
53 |
classified_foods.setdefault("unknown", []).append(food)
|
54 |
|
55 |
+
#classified_foods["vegetables"].sort()
|
56 |
|
57 |
+
result = []
|
58 |
+
for category, foods in classified_foods.items():
|
59 |
+
if foods:
|
60 |
+
result.append(f"{category.capitalize()}: {', '.join(foods)}")
|
61 |
+
|
62 |
+
return "Food classification:\n" + "\n".join(result)
|