SergeyO7 commited on
Commit
1e2c2de
·
verified ·
1 Parent(s): 99cbe07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -63,9 +63,6 @@ async def check_n_load_attach(session: aiohttp.ClientSession, task_id: str, api_
63
  await file.write(chunk)
64
  print(f"File downloaded successfully: {local_file_path}")
65
  return local_file_path
66
- else:
67
- print(f"No attachment found for task {task_id}")
68
- return None
69
  except aiohttp.ClientError as e:
70
  print(f"Error downloading attachment for task {task_id}: {str(e)}")
71
  return None
@@ -108,7 +105,7 @@ async def process_question(agent, question_text: str, task_id: str, file_path: O
108
  """Process a single question with global rate limiting and retry logic."""
109
  submitted_answer = None
110
  max_retries = 5
111
- retry_delay = 30 # Initial retry delay in seconds (increased for Gemini's 15s suggestion)
112
 
113
  for attempt in range(max_retries):
114
  try:
@@ -118,7 +115,7 @@ async def process_question(agent, question_text: str, task_id: str, file_path: O
118
  print(f"Processing task {task_id} (attempt {attempt + 1})...")
119
  submitted_answer = await asyncio.wait_for(
120
  agent(question_text, file_path),
121
- timeout=120 # Increased timeout for audio processing
122
  )
123
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
124
  print(f"Completed task {task_id} with answer: {submitted_answer[:50]}...")
@@ -135,7 +132,7 @@ async def process_question(agent, question_text: str, task_id: str, file_path: O
135
  print(f"Failed task {task_id}: {submitted_answer}")
136
  return None
137
  except asyncio.TimeoutError:
138
- submitted_answer = f"AGENT ERROR: Timeout after 120 seconds"
139
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
140
  print(f"Failed task {task_id}: {submitted_answer}")
141
  return None
@@ -183,7 +180,6 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
183
  answers_payload = []
184
  print(f"Running agent on {len(questions_data)} questions...")
185
 
186
- tasks = []
187
  for item in questions_data:
188
  task_id = item.get("task_id")
189
  question_text = item.get("question")
@@ -191,11 +187,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
191
  print(f"Skipping item with missing task_id or question: {item}")
192
  continue
193
  file_path = await check_n_load_attach(session, task_id)
194
- tasks.append(process_question(agent, question_text, task_id, file_path, results_log))
195
-
196
- # Wait for all tasks to complete
197
- results = await asyncio.gather(*tasks)
198
- for result in results:
199
  if result:
200
  answers_payload.append(result)
201
 
 
63
  await file.write(chunk)
64
  print(f"File downloaded successfully: {local_file_path}")
65
  return local_file_path
 
 
 
66
  except aiohttp.ClientError as e:
67
  print(f"Error downloading attachment for task {task_id}: {str(e)}")
68
  return None
 
105
  """Process a single question with global rate limiting and retry logic."""
106
  submitted_answer = None
107
  max_retries = 5
108
+ retry_delay = 30 # Initial retry delay in seconds
109
 
110
  for attempt in range(max_retries):
111
  try:
 
115
  print(f"Processing task {task_id} (attempt {attempt + 1})...")
116
  submitted_answer = await asyncio.wait_for(
117
  agent(question_text, file_path),
118
+ timeout=300 # Increased timeout for audio processing
119
  )
120
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
121
  print(f"Completed task {task_id} with answer: {submitted_answer[:50]}...")
 
132
  print(f"Failed task {task_id}: {submitted_answer}")
133
  return None
134
  except asyncio.TimeoutError:
135
+ submitted_answer =<JsonHighlight> f"AGENT ERROR: Timeout after 300 seconds"
136
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
137
  print(f"Failed task {task_id}: {submitted_answer}")
138
  return None
 
180
  answers_payload = []
181
  print(f"Running agent on {len(questions_data)} questions...")
182
 
 
183
  for item in questions_data:
184
  task_id = item.get("task_id")
185
  question_text = item.get("question")
 
187
  print(f"Skipping item with missing task_id or question: {item}")
188
  continue
189
  file_path = await check_n_load_attach(session, task_id)
190
+ result = await process_question(agent, question_text, task_id, file_path, results_log)
 
 
 
 
191
  if result:
192
  answers_payload.append(result)
193