Isaac454 commited on
Commit
9e8ab76
·
verified ·
1 Parent(s): 1c36231

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -64
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -8,86 +8,38 @@ from Gradio_UI import GradioUI
8
 
9
 
10
  @tool
11
- def translate_english_to_french(text: str) -> str:
12
  """
13
- Translates English text into French.
14
 
15
  Args:
16
- text (str): English text to be translated.
 
17
 
18
- Returns:
19
- str: The translated French text.
20
  """
21
- local_model = HfApiModel(
22
- model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
23
- max_tokens=256,
24
- temperature=0.2,
25
- )
26
-
27
- response = local_model(
28
- f"Translate the following English text into French. "
29
- f"Output only the translation:\n{text}"
30
- )
31
-
32
- return response
33
-
34
-
35
-
36
 
37
  @tool
38
- def get_current_time_in_timezone(timezone: str) -> str:
39
  """
40
- Fetches the current local time for a given timezone.
41
 
42
  Args:
43
- timezone (str): A valid IANA timezone string
44
- (for example: "America/New_York", "Europe/Paris", "Africa/Lagos").
45
 
46
- Returns:
47
- str: The current local time in the specified timezone.
48
  """
49
- try:
50
- tz = pytz.timezone(timezone)
51
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
52
- return f"The current local time in {timezone} is: {local_time}"
53
- except Exception as e:
54
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
55
-
56
 
57
 
58
  final_answer = FinalAnswerTool()
59
 
60
- model = HfApiModel(
61
- max_tokens=2096,
62
- temperature=0.5,
63
- model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
64
- custom_role_conversions=None,
65
- )
66
-
67
- # Import tool from Hub
68
- image_generation_tool = load_tool(
69
- "agents-course/text-to-image", trust_remote_code=True
70
- )
71
-
72
- with open("prompts.yaml", "r") as stream:
73
- prompt_templates = yaml.safe_load(stream)
74
 
75
- # 🔴 🔴 🔴 THIS IS THE ONLY CHANGE 🔴 🔴 🔴
76
- agent = CodeAgent(
77
  model=model,
78
- tools=[
79
- final_answer, # REQUIRED – do not remove
80
- translate_english_to_french,
81
- get_current_time_in_timezone,
82
- image_generation_tool # 🔴 ADDED HERE
83
- ],
84
- max_steps=6,
85
- verbosity_level=1,
86
- grammar=None,
87
- planning_interval=None,
88
- name=None,
89
- description=None,
90
- prompt_templates=prompt_templates
91
  )
92
 
93
- GradioUI(agent).launch()
 
1
+ from smolagents import Tool, FinalAnswerTool, ToolCallingAgent, DuckDuckGoSearchTool, tool, LiteLLMModel, PythonInterpreterTool, InferenceClientModel
2
  import datetime
3
  import requests
4
  import pytz
 
8
 
9
 
10
  @tool
11
+ def sum_tool(a: float, b: float) -> float:
12
  """
13
+ Returns the sum of two numbers
14
 
15
  Args:
16
+ a: The first value.
17
+ b: The second value.
18
 
 
 
19
  """
20
+ return a + b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  @tool
23
+ def sub_tool(a: float, b: float) -> float:
24
  """
25
+ Returns the difference of two numbers
26
 
27
  Args:
28
+ a: The first value.
29
+ b: The second value.
30
 
 
 
31
  """
32
+ return a - b
 
 
 
 
 
 
33
 
34
 
35
  final_answer = FinalAnswerTool()
36
 
37
+ model = LiteLLMModel(model_id="huggingface/google/gemma-2-2b-it")
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ agent = ToolCallingAgent(
40
+ tools=[sum_tool, sub_tool, PythonInterpreterTool()],
41
  model=model,
42
+ max_steps=3
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
 
45
+ GradioUI(agent).launch()