Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,7 +49,9 @@ def generate_answer(question: str, context: str = "") -> str:
|
|
| 49 |
with torch.no_grad():
|
| 50 |
outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
return response.strip()
|
| 54 |
|
| 55 |
class BasicAgent:
|
|
@@ -104,6 +106,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 104 |
except Exception as e:
|
| 105 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 106 |
|
|
|
|
|
|
|
|
|
|
| 107 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 108 |
try:
|
| 109 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
|
@@ -117,6 +122,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 117 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 118 |
)
|
| 119 |
return final_status, pd.DataFrame(results_log)
|
|
|
|
|
|
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
| 122 |
|
|
|
|
| 49 |
with torch.no_grad():
|
| 50 |
outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
| 51 |
|
| 52 |
+
# Fixed 2D tensor slice: batch index 0, starting after prompt token length
|
| 53 |
+
generated_tokens = outputs[0][inputs.input_ids.shape[1]:]
|
| 54 |
+
response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
|
| 55 |
return response.strip()
|
| 56 |
|
| 57 |
class BasicAgent:
|
|
|
|
| 106 |
except Exception as e:
|
| 107 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 108 |
|
| 109 |
+
if not answers_payload:
|
| 110 |
+
return "Agent failed on all questions (0 answers produced). Check table below for errors.", pd.DataFrame(results_log)
|
| 111 |
+
|
| 112 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 113 |
try:
|
| 114 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
|
|
|
| 122 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 123 |
)
|
| 124 |
return final_status, pd.DataFrame(results_log)
|
| 125 |
+
except requests.exceptions.HTTPError as e:
|
| 126 |
+
detail = e.response.text[:500]
|
| 127 |
+
return f"Submission Failed ({e.response.status_code}): {detail}", pd.DataFrame(results_log)
|
| 128 |
except Exception as e:
|
| 129 |
return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
| 130 |
|