theakshayrane commited on
Commit
d0575fc
·
verified ·
1 Parent(s): 9356300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -25,7 +25,7 @@ def document_parser_tool(file_path_or_url: str) -> str:
25
  if file_path_or_url.startswith('http'):
26
  local_path = "temp_financial_doc.pdf"
27
  urllib.request.urlretrieve(file_path_or_url, local_path)
28
-
29
  extracted_text = ""
30
  with open(local_path, 'rb') as file:
31
  reader = PyPDF2.PdfReader(file)
@@ -77,12 +77,14 @@ class BasicAgent:
77
  self.model = OpenAIServerModel(
78
  model_id="llama-3.3-70b-versatile",
79
  api_base="https://api.groq.com/openai/v1",
80
- api_key=os.environ.get("GROQ_API_KEY")
 
81
  )
82
 
83
  self.agent = CodeAgent(
84
  tools=[self.search_tool, document_parser_tool, visit_webpage_tool],
85
  model=self.model,
 
86
  additional_authorized_imports=[
87
  "math", "pandas", "datetime", "requests", "bs4", "re", "time"
88
  ]
@@ -175,15 +177,16 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
175
  # 3. Run your Agent
176
  results_log = []
177
  answers_payload = []
178
- print(f"Running agent on {len(questions_data)} questions...")
179
- for item in questions_data:
 
 
180
  task_id = item.get("task_id")
181
  question_text = item.get("question")
182
  if not task_id or question_text is None:
183
  print(f"Skipping item with missing task_id or question: {item}")
184
  continue
185
  try:
186
- # ---> UPDATED LINE HERE: Passing task_id <---
187
  submitted_answer = agent(task_id, question_text)
188
 
189
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
@@ -191,8 +194,10 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
191
  except Exception as e:
192
  print(f"Error running agent on task {task_id}: {e}")
193
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
194
- time.sleep(10)
195
-
 
 
196
  if not answers_payload:
197
  print("Agent did not produce any answers to submit.")
198
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
@@ -245,7 +250,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
245
  results_df = pd.DataFrame(results_log)
246
  return status_message, results_df
247
 
248
-
249
  # --- Build Gradio Interface using Blocks ---
250
  with gr.Blocks() as demo:
251
  gr.Markdown("# Financial Due Diligence Agent Evaluation Runner")
@@ -255,9 +259,6 @@ with gr.Blocks() as demo:
255
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
256
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
257
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
258
- ---
259
- **Disclaimers:**
260
- Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
261
  """
262
  )
263
 
 
25
  if file_path_or_url.startswith('http'):
26
  local_path = "temp_financial_doc.pdf"
27
  urllib.request.urlretrieve(file_path_or_url, local_path)
28
+
29
  extracted_text = ""
30
  with open(local_path, 'rb') as file:
31
  reader = PyPDF2.PdfReader(file)
 
77
  self.model = OpenAIServerModel(
78
  model_id="llama-3.3-70b-versatile",
79
  api_base="https://api.groq.com/openai/v1",
80
+ api_key=os.environ.get("GROQ_API_KEY"),
81
+ max_retries=1 # <--- ADDED: Stops infinite hanging on API limits
82
  )
83
 
84
  self.agent = CodeAgent(
85
  tools=[self.search_tool, document_parser_tool, visit_webpage_tool],
86
  model=self.model,
87
+ max_steps=4, # <--- ADDED: Forces the agent to give up and move on if stuck
88
  additional_authorized_imports=[
89
  "math", "pandas", "datetime", "requests", "bs4", "re", "time"
90
  ]
 
177
  # 3. Run your Agent
178
  results_log = []
179
  answers_payload = []
180
+
181
+ # ---> ADDED: [:1] forces "Test Mode" to only run the VERY FIRST question <---
182
+ print(f"Running agent on 1 test question...")
183
+ for item in questions_data[:1]:
184
  task_id = item.get("task_id")
185
  question_text = item.get("question")
186
  if not task_id or question_text is None:
187
  print(f"Skipping item with missing task_id or question: {item}")
188
  continue
189
  try:
 
190
  submitted_answer = agent(task_id, question_text)
191
 
192
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
 
194
  except Exception as e:
195
  print(f"Error running agent on task {task_id}: {e}")
196
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
197
+
198
+ # ---> CHANGED: Reduced sleep time since Groq is fast <---
199
+ time.sleep(2)
200
+
201
  if not answers_payload:
202
  print("Agent did not produce any answers to submit.")
203
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
250
  results_df = pd.DataFrame(results_log)
251
  return status_message, results_df
252
 
 
253
  # --- Build Gradio Interface using Blocks ---
254
  with gr.Blocks() as demo:
255
  gr.Markdown("# Financial Due Diligence Agent Evaluation Runner")
 
259
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
260
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
261
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
 
 
262
  """
263
  )
264