Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -266,6 +266,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 266 |
return f"An unexpected error occurred loading questions: {e}", None
|
| 267 |
|
| 268 |
# 3. Run your Agent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
results_log = []
|
| 270 |
answers_payload = []
|
| 271 |
print(f"Running agent on {len(questions_data)} questions...")
|
|
@@ -289,7 +296,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 289 |
+ file_content
|
| 290 |
)
|
| 291 |
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
if submitted_answer is None:
|
| 294 |
raise ValueError("Submitted answer is None")
|
| 295 |
if not isinstance(submitted_answer, (str, int, float)):
|
|
|
|
| 266 |
return f"An unexpected error occurred loading questions: {e}", None
|
| 267 |
|
| 268 |
# 3. Run your Agent
|
| 269 |
+
cache_file = Path("answers_cache.json")
|
| 270 |
+
|
| 271 |
+
if cache_file.exists():
|
| 272 |
+
with open(cache_file, "r", encoding="utf-8") as f:
|
| 273 |
+
saved_answers = json.load(f)
|
| 274 |
+
else:
|
| 275 |
+
saved_answers = {}
|
| 276 |
results_log = []
|
| 277 |
answers_payload = []
|
| 278 |
print(f"Running agent on {len(questions_data)} questions...")
|
|
|
|
| 296 |
+ file_content
|
| 297 |
)
|
| 298 |
|
| 299 |
+
if task_id in saved_answers:
|
| 300 |
+
submitted_answer = saved_answers[task_id]
|
| 301 |
+
print(f"Using cached answer for {task_id}")
|
| 302 |
+
else:
|
| 303 |
+
submitted_answer = agent(agent_question)
|
| 304 |
+
|
| 305 |
+
if submitted_answer is not None:
|
| 306 |
+
saved_answers[task_id] = submitted_answer
|
| 307 |
+
|
| 308 |
+
with open(cache_file, "w", encoding="utf-8") as f:
|
| 309 |
+
json.dump(saved_answers, f, ensure_ascii=False, indent=2)
|
| 310 |
if submitted_answer is None:
|
| 311 |
raise ValueError("Submitted answer is None")
|
| 312 |
if not isinstance(submitted_answer, (str, int, float)):
|