Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,38 +10,24 @@ from Gradio_UI import GradioUI
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
def food_nutrition(food: str) -> str:
|
13 |
-
"""
|
14 |
-
|
15 |
-
|
|
|
16 |
Args:
|
17 |
-
food: A string representing a food item.
|
18 |
-
|
19 |
Returns:
|
20 |
-
|
21 |
"""
|
22 |
try:
|
23 |
search_tool = DuckDuckGoSearchTool() # Requires smolagents
|
24 |
query = f"Nutritional facts per 100g of {food} (calories, fat, carbs, protein)"
|
25 |
results = search_tool(query)
|
26 |
-
|
27 |
if results:
|
28 |
-
|
29 |
-
# For now, here are mock placeholders:
|
30 |
-
calories = "XXX kcal"
|
31 |
-
fat = "YY g"
|
32 |
-
carbs = "ZZ g"
|
33 |
-
protein = "WW g"
|
34 |
-
|
35 |
-
return (
|
36 |
-
f"Nutritional information for 100g of {food}:\n"
|
37 |
-
f" * Calories: {calories}\n"
|
38 |
-
f" * Fat: {fat}\n"
|
39 |
-
f" * Carbs: {carbs}\n"
|
40 |
-
f" * Protein: {protein}"
|
41 |
-
)
|
42 |
else:
|
43 |
return f"Sorry, I couldn't find any nutritional data for {food}."
|
44 |
-
|
45 |
except Exception as e:
|
46 |
return f"Error fetching nutritional facts for '{food}': {e}. Please check the spelling or try another food."
|
47 |
|
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
def food_nutrition(food: str) -> str:
|
13 |
+
"""
|
14 |
+
A tool that takes a food name as input and performs a web search
|
15 |
+
to find its nutritional facts (calories, fat, carbs, and protein) per 100g.
|
16 |
+
|
17 |
Args:
|
18 |
+
food (str): A string representing a food item.
|
19 |
+
|
20 |
Returns:
|
21 |
+
str: The raw nutritional information retrieved by the search query.
|
22 |
"""
|
23 |
try:
|
24 |
search_tool = DuckDuckGoSearchTool() # Requires smolagents
|
25 |
query = f"Nutritional facts per 100g of {food} (calories, fat, carbs, protein)"
|
26 |
results = search_tool(query)
|
|
|
27 |
if results:
|
28 |
+
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
else:
|
30 |
return f"Sorry, I couldn't find any nutritional data for {food}."
|
|
|
31 |
except Exception as e:
|
32 |
return f"Error fetching nutritional facts for '{food}': {e}. Please check the spelling or try another food."
|
33 |
|