Arno' Francesco (GDS DS&G) commited on
Commit
64c23f8
·
1 Parent(s): 8ba79a3

add more imports

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +19 -5
.gitignore CHANGED
@@ -5,3 +5,4 @@ test.py
5
  __pycache__/
6
  f918266a-b3e0-4914-865d-4faa564f1aef.py
7
  *.env
 
 
5
  __pycache__/
6
  f918266a-b3e0-4914-865d-4faa564f1aef.py
7
  *.env
8
+ answers_*.json
app.py CHANGED
@@ -11,6 +11,7 @@ import time
11
  import datetime
12
  from utils import download_file
13
  from dotenv import load_dotenv
 
14
 
15
  load_dotenv()
16
 
@@ -60,8 +61,8 @@ class BasicAgent:
60
  #model = InferenceClientModel()
61
 
62
  response = litellm.completion(
63
- #model="gemini/gemini-2.0-flash",
64
- model="gemini/gemini-2.0-flash-lite",
65
  messages=messages,
66
  )
67
 
@@ -76,7 +77,7 @@ class BasicAgent:
76
  tools=[calculator_tool],
77
  managed_agents=[self.web_agent, describe_audio, describe_image, read_excel_file, read_python_file],
78
  model=self.model,
79
- additional_authorized_imports=["pandas", "re", "requests", "json", "numpy"],
80
  max_steps=10,
81
  verbosity_level=2,
82
  planning_interval=5,
@@ -155,15 +156,26 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
155
  submitted_answer = agent(question_text)
156
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
157
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
158
  except Exception as e:
159
  print(f"Error running agent on task {task_id}: {e}")
160
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
161
 
162
- time.sleep(60)
163
 
164
  if not answers_payload:
165
  print("Agent did not produce any answers to submit.")
166
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
 
 
 
 
 
 
 
 
 
167
 
168
  # 4. Prepare Submission
169
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
@@ -211,7 +223,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
211
  status_message = f"An unexpected error occurred during submission: {e}"
212
  print(status_message)
213
  results_df = pd.DataFrame(results_log)
214
- return status_message, results_df
 
 
215
 
216
 
217
  # --- Build Gradio Interface using Blocks ---
 
11
  import datetime
12
  from utils import download_file
13
  from dotenv import load_dotenv
14
+ import json
15
 
16
  load_dotenv()
17
 
 
61
  #model = InferenceClientModel()
62
 
63
  response = litellm.completion(
64
+ model="gemini/gemini-2.0-flash",
65
+ #model="gemini/gemini-2.0-flash-lite",
66
  messages=messages,
67
  )
68
 
 
77
  tools=[calculator_tool],
78
  managed_agents=[self.web_agent, describe_audio, describe_image, read_excel_file, read_python_file],
79
  model=self.model,
80
+ additional_authorized_imports=["pandas", "re", "requests", "json", "numpy", "bs4", "datetime", "os", "io", "csv"],
81
  max_steps=10,
82
  verbosity_level=2,
83
  planning_interval=5,
 
156
  submitted_answer = agent(question_text)
157
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
158
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
159
+
160
  except Exception as e:
161
  print(f"Error running agent on task {task_id}: {e}")
162
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
163
 
164
+ time.sleep(100)
165
 
166
  if not answers_payload:
167
  print("Agent did not produce any answers to submit.")
168
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
169
+
170
+ # 6. Save answers to json
171
+ try:
172
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
173
+ filename = f"answers_{timestamp}.json"
174
+ with open(filename, "w") as f:
175
+ json.dump(answers_payload, f)
176
+ print(f"Answers saved to {filename}")
177
+ except Exception as e:
178
+ print(f"Error saving answers to file: {e}")
179
 
180
  # 4. Prepare Submission
181
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
223
  status_message = f"An unexpected error occurred during submission: {e}"
224
  print(status_message)
225
  results_df = pd.DataFrame(results_log)
226
+ return status_message, results_df
227
+
228
+
229
 
230
 
231
  # --- Build Gradio Interface using Blocks ---