Update app.py
Browse filesAttempt to read locally cached copies of the question files
app.py
CHANGED
@@ -37,7 +37,7 @@ class AudioDescriptionTool(Tool):
|
|
37 |
inputs = {
|
38 |
"file_name": {
|
39 |
"type": "string",
|
40 |
-
"description": "
|
41 |
}
|
42 |
}
|
43 |
output_type = "string"
|
@@ -57,59 +57,59 @@ class AudioDescriptionTool(Tool):
|
|
57 |
|
58 |
audio_description_tool = AudioDescriptionTool()
|
59 |
|
60 |
-
class FetchFileTool(Tool):
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
|
112 |
-
fetch_file_tool = FetchFileTool()
|
113 |
|
114 |
class WikipediaSearchTool(Tool):
|
115 |
name = "wikipedia_search"
|
@@ -166,7 +166,7 @@ class BasicAgent:
|
|
166 |
prompt_templates = yaml.safe_load(stream)
|
167 |
self.agent = CodeAgent(
|
168 |
model=model,
|
169 |
-
tools=[final_answer, search_tool, wiki_tool,
|
170 |
max_steps=7,
|
171 |
verbosity_level=1,
|
172 |
additional_authorized_imports=[
|
@@ -264,7 +264,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
264 |
# 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3"
|
265 |
if item.get("task_id") == "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3":
|
266 |
# if item.get("file_name"):
|
267 |
-
question_text = f"{question_text} Here is the file: https://agents-course-unit4-scoring.hf.space/files/{item.get('task_id')}"
|
|
|
268 |
else:
|
269 |
continue
|
270 |
submitted_answer = agent(question_text)
|
|
|
37 |
inputs = {
|
38 |
"file_name": {
|
39 |
"type": "string",
|
40 |
+
"description": "Complete name of the local file to describe, for example: /files/98c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea8.mp3",
|
41 |
}
|
42 |
}
|
43 |
output_type = "string"
|
|
|
57 |
|
58 |
audio_description_tool = AudioDescriptionTool()
|
59 |
|
60 |
+
# class FetchFileTool(Tool):
|
61 |
+
# name = "file_saver"
|
62 |
+
# description = """
|
63 |
+
# This is a tool that will fetch an internet file and save content locally.
|
64 |
+
# It takes a location, file path, file name, and content to save."""
|
65 |
+
# inputs = {
|
66 |
+
# "location": {
|
67 |
+
# "type": "string",
|
68 |
+
# "description": "The internet location of the file to fetch",
|
69 |
+
# },
|
70 |
+
# "file_extension": {
|
71 |
+
# "type": "string",
|
72 |
+
# "description": "Assumed file extension of the file to fetch, like mp3 or png for example",
|
73 |
+
# },
|
74 |
+
# "file_path": {
|
75 |
+
# "type": "string",
|
76 |
+
# "description": "The path to the directory where the file will be saved",
|
77 |
+
# },
|
78 |
+
# "file_name": {
|
79 |
+
# "type": "string",
|
80 |
+
# "description": "The name of the file where content will be saved",
|
81 |
+
# }
|
82 |
+
# }
|
83 |
+
# output_type = "boolean"
|
84 |
|
85 |
+
# def forward(self, location: str, file_extension: str, file_path: str, file_name: str):
|
86 |
+
# try:
|
87 |
+
# response = requests.get(location)
|
88 |
+
# response.raise_for_status()
|
89 |
+
# content = response.content
|
90 |
+
# full_path = os.path.join(file_path, file_name)
|
91 |
+
# with open(full_path, 'wb') as out_file:
|
92 |
+
# out_file.write(content)
|
93 |
+
# return True
|
94 |
|
95 |
+
# except Exception as e:
|
96 |
+
# # if error is HTTP 429 then copy from /files
|
97 |
+
# if response.status_code == 429:
|
98 |
+
# # get last part of location separated by slash
|
99 |
+
# file_id = location.split('/')[-1]
|
100 |
+
# local_path = f"files/{file_id}.{file_extension}"
|
101 |
+
# print(f"Copying from: {local_path}")
|
102 |
+
|
103 |
+
# full_path = os.path.join(file_path, file_name)
|
104 |
+
# print(f"Copying to: {full_path}")
|
105 |
+
|
106 |
+
# shutil.copy(local_path, full_path)
|
107 |
+
# return True
|
108 |
+
# else:
|
109 |
+
# print(f"Error saving content to file: {e}")
|
110 |
+
# return False
|
111 |
|
112 |
+
# fetch_file_tool = FetchFileTool()
|
113 |
|
114 |
class WikipediaSearchTool(Tool):
|
115 |
name = "wikipedia_search"
|
|
|
166 |
prompt_templates = yaml.safe_load(stream)
|
167 |
self.agent = CodeAgent(
|
168 |
model=model,
|
169 |
+
tools=[final_answer, search_tool, wiki_tool, audio_description_tool],
|
170 |
max_steps=7,
|
171 |
verbosity_level=1,
|
172 |
additional_authorized_imports=[
|
|
|
264 |
# 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3"
|
265 |
if item.get("task_id") == "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3":
|
266 |
# if item.get("file_name"):
|
267 |
+
# question_text = f"{question_text} Here is the file: https://agents-course-unit4-scoring.hf.space/files/{item.get('task_id')}"
|
268 |
+
question_text = f"{question_text} Here is the file: /files/{item.get('task_id')}"
|
269 |
else:
|
270 |
continue
|
271 |
submitted_answer = agent(question_text)
|