Thanh Vinh Vo commited on
Commit
83b34ee
·
1 Parent(s): 5f7b40f
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -26,13 +26,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
26
 
27
 
28
  @tool
29
- def get_file_location(file_name: str) -> str:
30
  """
31
- A tool that resolve the file URL for a question.
32
  Args:
33
  file_name: File name.
34
  """
35
- return f"{DEFAULT_API_URL}/files/{file_name}"
 
 
 
 
 
36
 
37
 
38
  # --- Basic Agent Definition ---
@@ -41,7 +46,7 @@ class BasicAgent:
41
  def __init__(self):
42
  print("BasicAgent initialized.")
43
  self.multimodal_agent = CodeAgent(
44
- tools=[VisitWebpageTool(), DuckDuckGoSearchTool(), get_file_location],
45
  model=InferenceClientModel(
46
  model_id="meta-llama/Llama-3.2-11B-Vision-Instruct",
47
  ),
@@ -70,7 +75,7 @@ class BasicAgent:
70
  )
71
 
72
  self.code_agent = CodeAgent(
73
- tools=[VisitWebpageTool(), DuckDuckGoSearchTool(), get_file_location],
74
  model=InferenceClientModel(
75
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
76
  ),
@@ -92,7 +97,11 @@ class BasicAgent:
92
  "chess.engine",
93
  ],
94
  name="code_agent",
95
- description="I am strong at writing code to solve problem.",
 
 
 
 
96
  verbosity_level=0,
97
  max_steps=10,
98
  )
@@ -101,7 +110,7 @@ class BasicAgent:
101
  model=InferenceClientModel(
102
  "Qwen/Qwen2.5-32B-Instruct"
103
  ),
104
- tools=[VisitWebpageTool(), DuckDuckGoSearchTool(), get_file_location],
105
  managed_agents=[
106
  self.multimodal_agent,
107
  self.code_agent],
 
26
 
27
 
28
  @tool
29
+ def get_image(file_name: str) -> Image.Image:
30
  """
31
+ A tool that load image from file name.
32
  Args:
33
  file_name: File name.
34
  """
35
+ import requests
36
+ from PIL import Image
37
+ from io import BytesIO
38
+ url = f"{DEFAULT_API_URL}/files/{file_name}"
39
+ response = requests.get(url)
40
+ return Image.open(BytesIO(response.content)).convert("RGB")
41
 
42
 
43
  # --- Basic Agent Definition ---
 
46
  def __init__(self):
47
  print("BasicAgent initialized.")
48
  self.multimodal_agent = CodeAgent(
49
+ tools=[VisitWebpageTool(), DuckDuckGoSearchTool()],
50
  model=InferenceClientModel(
51
  model_id="meta-llama/Llama-3.2-11B-Vision-Instruct",
52
  ),
 
75
  )
76
 
77
  self.code_agent = CodeAgent(
78
+ tools=[VisitWebpageTool(), DuckDuckGoSearchTool(), get_image],
79
  model=InferenceClientModel(
80
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
81
  ),
 
97
  "chess.engine",
98
  ],
99
  name="code_agent",
100
+ description="""
101
+ I am strong at:
102
+ - Writing code to solve problem.
103
+ - Browse the web to find information.
104
+ """,
105
  verbosity_level=0,
106
  max_steps=10,
107
  )
 
110
  model=InferenceClientModel(
111
  "Qwen/Qwen2.5-32B-Instruct"
112
  ),
113
+ tools=[get_image],
114
  managed_agents=[
115
  self.multimodal_agent,
116
  self.code_agent],