Thanh Vinh Vo
commited on
Commit
·
d5bc8fc
1
Parent(s):
c5121cf
update
Browse files
app.py
CHANGED
|
@@ -26,33 +26,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 26 |
|
| 27 |
|
| 28 |
@tool
|
| 29 |
-
def
|
| 30 |
"""
|
| 31 |
-
A tool that
|
| 32 |
Args:
|
| 33 |
-
file_name: File name
|
| 34 |
"""
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
import requests
|
| 38 |
-
from PIL import Image
|
| 39 |
-
|
| 40 |
-
try:
|
| 41 |
-
# Construct the API endpoint URL for file retrieval
|
| 42 |
-
file_url = f"{DEFAULT_API_URL}/files/{file_name}"
|
| 43 |
-
|
| 44 |
-
# Make GET request to retrieve file contents
|
| 45 |
-
response = requests.get(file_url, timeout=30)
|
| 46 |
-
response.raise_for_status()
|
| 47 |
-
|
| 48 |
-
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 49 |
-
# Return the file contents as text
|
| 50 |
-
return image
|
| 51 |
-
|
| 52 |
-
except requests.exceptions.RequestException as e:
|
| 53 |
-
print(f"Error retrieving file '{file_name}': {e}")
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(f"Unexpected error retrieving file '{file_name}': {e}")
|
| 56 |
|
| 57 |
|
| 58 |
# --- Basic Agent Definition ---
|
|
@@ -61,7 +41,7 @@ class BasicAgent:
|
|
| 61 |
def __init__(self):
|
| 62 |
print("BasicAgent initialized.")
|
| 63 |
self.multimodal_agent = CodeAgent(
|
| 64 |
-
tools=[VisitWebpageTool(), DuckDuckGoSearchTool(),
|
| 65 |
model=InferenceClientModel(
|
| 66 |
model_id="meta-llama/Llama-3.2-11B-Vision-Instruct",
|
| 67 |
),
|
|
@@ -83,7 +63,7 @@ class BasicAgent:
|
|
| 83 |
)
|
| 84 |
|
| 85 |
self.code_agent = CodeAgent(
|
| 86 |
-
tools=[VisitWebpageTool(), DuckDuckGoSearchTool(),
|
| 87 |
model=InferenceClientModel(
|
| 88 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 89 |
),
|
|
|
|
| 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 |
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 |
),
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
self.code_agent = CodeAgent(
|
| 66 |
+
tools=[VisitWebpageTool(), DuckDuckGoSearchTool(), get_file_location],
|
| 67 |
model=InferenceClientModel(
|
| 68 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 69 |
),
|