mrpe24 commited on
Commit
34bc852
·
1 Parent(s): 256ce28

fixed file downloading

Browse files
agentcourse_unit4/api/agent_eval_api.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import urllib.request
2
  from typing import List
3
 
@@ -21,12 +22,13 @@ class AgentEvalApi:
21
  response.raise_for_status()
22
  return response.json(object_hook=to_question_response)
23
 
24
- def download_file(self, task_id: str) -> str:
25
  """Download the file associated with the given task_id to temp dir and return path to file"""
26
  file_path = None
27
 
28
  try:
29
- result = urllib.request.urlretrieve(f"{self.files_url}/{task_id}")
 
30
  file_path = result[0]
31
  except Exception as e:
32
  print(f"Error downloading file: {str(e)}")
 
1
+ import tempfile
2
  import urllib.request
3
  from typing import List
4
 
 
22
  response.raise_for_status()
23
  return response.json(object_hook=to_question_response)
24
 
25
+ def download_file(self, task_id: str, file_name: str) -> str:
26
  """Download the file associated with the given task_id to temp dir and return path to file"""
27
  file_path = None
28
 
29
  try:
30
+ path_to_file = f"{tempfile.gettempdir()}/{file_name}"
31
+ result = urllib.request.urlretrieve(f"{self.files_url}/{task_id}", filename=path_to_file)
32
  file_path = result[0]
33
  except Exception as e:
34
  print(f"Error downloading file: {str(e)}")
app.py CHANGED
@@ -70,7 +70,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
70
  continue
71
 
72
  try:
73
- file_path = api_client.download_file(task_id) if len(file_name) > 0 else None
74
  submitted_answer = agent.run(question_text, file_path)
75
  answers_payload.append(AnswerData(task_id=task_id, answer=str(submitted_answer)))
76
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
70
  continue
71
 
72
  try:
73
+ file_path = api_client.download_file(task_id, file_name) if len(file_name) > 0 else None
74
  submitted_answer = agent.run(question_text, file_path)
75
  answers_payload.append(AnswerData(task_id=task_id, answer=str(submitted_answer)))
76
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})