Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,6 +29,7 @@ token_bucket = Limiter(rate=TOKEN_BUCKET_REFILL_RATE, capacity=TOKEN_BUCKET_CAPA
|
|
| 29 |
async def check_n_load_attach(session: aiohttp.ClientSession, task_id: str, api_url: str = DEFAULT_API_URL) -> Optional[str]:
|
| 30 |
file_url = f"{api_url}/files/{task_id}"
|
| 31 |
try:
|
|
|
|
| 32 |
async with session.get(file_url, timeout=15) as response:
|
| 33 |
if response.status == 200:
|
| 34 |
# Get filename from Content-Disposition
|
|
@@ -185,24 +186,21 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 185 |
answers_payload = []
|
| 186 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 187 |
|
|
|
|
| 188 |
for item in questions_data:
|
| 189 |
task_id = item.get("task_id")
|
| 190 |
question_text = item.get("question")
|
| 191 |
if not task_id or question_text is None:
|
| 192 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 193 |
continue
|
| 194 |
-
# if "1ht" in question_text.lower() or "attach" in question_text.lower():
|
| 195 |
file_path = await check_n_load_attach(session, task_id)
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
if result:
|
| 198 |
answers_payload.append(result)
|
| 199 |
-
else:
|
| 200 |
-
print(f"Skipping not related question: {task_id}")
|
| 201 |
-
results_log.append({
|
| 202 |
-
"Task ID": task_id,
|
| 203 |
-
"Question": question_text,
|
| 204 |
-
"Submitted Answer": "Question skipped - not related"
|
| 205 |
-
})
|
| 206 |
|
| 207 |
if not answers_payload:
|
| 208 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 29 |
async def check_n_load_attach(session: aiohttp.ClientSession, task_id: str, api_url: str = DEFAULT_API_URL) -> Optional[str]:
|
| 30 |
file_url = f"{api_url}/files/{task_id}"
|
| 31 |
try:
|
| 32 |
+
|
| 33 |
async with session.get(file_url, timeout=15) as response:
|
| 34 |
if response.status == 200:
|
| 35 |
# Get filename from Content-Disposition
|
|
|
|
| 186 |
answers_payload = []
|
| 187 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 188 |
|
| 189 |
+
tasks = []
|
| 190 |
for item in questions_data:
|
| 191 |
task_id = item.get("task_id")
|
| 192 |
question_text = item.get("question")
|
| 193 |
if not task_id or question_text is None:
|
| 194 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 195 |
continue
|
|
|
|
| 196 |
file_path = await check_n_load_attach(session, task_id)
|
| 197 |
+
tasks.append(process_question(agent, question_text, task_id, file_path, results_log))
|
| 198 |
+
|
| 199 |
+
# Wait for all tasks to complete
|
| 200 |
+
results = await asyncio.gather(*tasks)
|
| 201 |
+
for result in results:
|
| 202 |
if result:
|
| 203 |
answers_payload.append(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
if not answers_payload:
|
| 206 |
print("Agent did not produce any answers to submit.")
|