RozzaCreat commited on
Commit
58ae99f
·
verified ·
1 Parent(s): e80f805

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -7,6 +7,45 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
  @tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
11
  #Keep this format for the description / args / args description but feel free to modify the tool
12
  """A tool that does nothing yet
@@ -73,7 +112,7 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
73
 
74
  # return response
75
 
76
-
77
  @tool
78
  def get_current_time_in_timezone(timezone: str) -> str:
79
  """A tool that fetches the current local time in a specified timezone.
 
7
 
8
  from Gradio_UI import GradioUI
9
  @tool
10
+
11
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+ @tool
13
+ def food_nutrition(food: str) -> str:
14
+ """A tool that takes a food name as input and performs a web search
15
+ to find its calories, fat, carbs, and protein per 100g.
16
+ Args:
17
+ food: A string representing a food item.
18
+ Returns:
19
+ A formatted string containing nutritional information.
20
+ """
21
+ try:
22
+ search_tool = DuckDuckGoSearchTool() # Requires smolagents
23
+ query = f"Nutritional facts per 100g of {food} (calories, fat, carbs, protein)"
24
+ results = search_tool(query)
25
+
26
+ if results:
27
+ # You will need to extract actual values from the results.
28
+ # For now, here are mock placeholders:
29
+ calories = "XXX kcal"
30
+ fat = "YY g"
31
+ carbs = "ZZ g"
32
+ protein = "WW g"
33
+
34
+ return (
35
+ f"Nutritional information for 100g of {food}:\n"
36
+ f" * Calories: {calories}\n"
37
+ f" * Fat: {fat}\n"
38
+ f" * Carbs: {carbs}\n"
39
+ f" * Protein: {protein}"
40
+ )
41
+ else:
42
+ return f"Sorry, I couldn't find any nutritional data for {food}."
43
+
44
+ except Exception as e:
45
+ return f"Error fetching nutritional facts for '{food}': {e}. Please check the spelling or try anothe
46
+
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
 
112
 
113
  # return response
114
 
115
+ '''
116
  @tool
117
  def get_current_time_in_timezone(timezone: str) -> str:
118
  """A tool that fetches the current local time in a specified timezone.