Update app.py
Browse files
app.py
CHANGED
|
@@ -82,44 +82,30 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 82 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 83 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 84 |
|
| 85 |
-
|
| 86 |
results_log = []
|
| 87 |
answers_payload = []
|
| 88 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 89 |
-
for
|
| 90 |
task_id = item.get("task_id")
|
| 91 |
question_text = item.get("question")
|
| 92 |
if not task_id or question_text is None:
|
| 93 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 94 |
continue
|
| 95 |
-
|
| 96 |
-
print(f"Processing question {idx}/{len(questions_data)} - Task ID: {task_id}")
|
| 97 |
try:
|
| 98 |
submitted_answer = agent(question_text)
|
| 99 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 100 |
-
results_log.append({
|
| 101 |
-
"Task ID": task_id,
|
| 102 |
-
"Question": question_text[:100] + "..." if len(question_text) > 100 else question_text,
|
| 103 |
-
"Submitted Answer": submitted_answer[:200] + "..." if len(submitted_answer) > 200 else submitted_answer
|
| 104 |
-
})
|
| 105 |
except Exception as e:
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
"Task ID": task_id,
|
| 109 |
-
"Question": question_text[:100] + "..." if len(question_text) > 100 else question_text,
|
| 110 |
-
"Submitted Answer": f"AGENT ERROR: {e}"
|
| 111 |
-
})
|
| 112 |
|
| 113 |
if not answers_payload:
|
| 114 |
print("Agent did not produce any answers to submit.")
|
| 115 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 116 |
|
| 117 |
# 4. Prepare Submission
|
| 118 |
-
submission_data = {
|
| 119 |
-
"username": username.strip(),
|
| 120 |
-
"agent_code": agent_code,
|
| 121 |
-
"answers": answers_payload
|
| 122 |
-
}
|
| 123 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 124 |
print(status_update)
|
| 125 |
|
|
@@ -180,8 +166,9 @@ with gr.Blocks() as demo:
|
|
| 180 |
**Agent Tools:**
|
| 181 |
- Mathematical operations (add, subtract, multiply, divide, modulus)
|
| 182 |
- Wikipedia search
|
| 183 |
-
- Web search (
|
| 184 |
- Arxiv academic paper search
|
|
|
|
| 185 |
|
| 186 |
**Note:** Processing all questions may take several minutes depending on the number of questions and API response times.
|
| 187 |
"""
|
|
@@ -206,8 +193,7 @@ if __name__ == "__main__":
|
|
| 206 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 207 |
space_id_startup = os.getenv("SPACE_ID")
|
| 208 |
google_api_key = os.getenv("GOOGLE_API_KEY")
|
| 209 |
-
|
| 210 |
-
|
| 211 |
if space_host_startup:
|
| 212 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 213 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
|
|
|
| 82 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 83 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 84 |
|
| 85 |
+
# 3. Run your Agent
|
| 86 |
results_log = []
|
| 87 |
answers_payload = []
|
| 88 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 89 |
+
for item in questions_data:
|
| 90 |
task_id = item.get("task_id")
|
| 91 |
question_text = item.get("question")
|
| 92 |
if not task_id or question_text is None:
|
| 93 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 94 |
continue
|
|
|
|
|
|
|
| 95 |
try:
|
| 96 |
submitted_answer = agent(question_text)
|
| 97 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 98 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 101 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
if not answers_payload:
|
| 104 |
print("Agent did not produce any answers to submit.")
|
| 105 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 106 |
|
| 107 |
# 4. Prepare Submission
|
| 108 |
+
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 110 |
print(status_update)
|
| 111 |
|
|
|
|
| 166 |
**Agent Tools:**
|
| 167 |
- Mathematical operations (add, subtract, multiply, divide, modulus)
|
| 168 |
- Wikipedia search
|
| 169 |
+
- Web search (DDGS)
|
| 170 |
- Arxiv academic paper search
|
| 171 |
+
- Web Scraping Tool using BeautifulSoup
|
| 172 |
|
| 173 |
**Note:** Processing all questions may take several minutes depending on the number of questions and API response times.
|
| 174 |
"""
|
|
|
|
| 193 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 194 |
space_id_startup = os.getenv("SPACE_ID")
|
| 195 |
google_api_key = os.getenv("GOOGLE_API_KEY")
|
| 196 |
+
|
|
|
|
| 197 |
if space_host_startup:
|
| 198 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 199 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|