Spaces:
Sleeping
Sleeping
food
Browse files
app.py
CHANGED
@@ -9,14 +9,51 @@ from Gradio_UI import GradioUI
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
9 |
|
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 |
+
"""A tool that takes a food name as input and performs a web search
|
14 |
+
to find its calories, fat, carbs, and protein per 100g.
|
15 |
+
|
16 |
Args:
|
17 |
+
food: A string representing a food item.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
A formatted string containing nutritional information.
|
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 |
+
# You will need to extract actual values from the results.
|
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 |
+
|
48 |
+
|
49 |
+
# def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
50 |
+
# #Keep this format for the description / args / args description but feel free to modify the tool
|
51 |
+
# """A tool that does nothing yet
|
52 |
+
# Args:
|
53 |
+
# arg1: the first argument
|
54 |
+
# arg2: the second argument
|
55 |
+
# """
|
56 |
+
# return "What magic will you build ?"
|
57 |
|
58 |
@tool
|
59 |
def get_current_time_in_timezone(timezone: str) -> str:
|