Spaces:
Sleeping
Sleeping
Update submit.py
Browse files
submit.py
CHANGED
|
@@ -57,3 +57,43 @@ def submit_answers(agent):
|
|
| 57 |
response = requests.post(f"{BASE_URL}/submit", json=payload)
|
| 58 |
print("Submitted! Status:", response.status_code)
|
| 59 |
print(response.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
response = requests.post(f"{BASE_URL}/submit", json=payload)
|
| 58 |
print("Submitted! Status:", response.status_code)
|
| 59 |
print(response.json())
|
| 60 |
+
|
| 61 |
+
def main(agent):
|
| 62 |
+
# your existing submission logic should go inside here
|
| 63 |
+
# e.g., load questions, run agent, collect answers, and submit via POST
|
| 64 |
+
|
| 65 |
+
# Here’s a simplified example:
|
| 66 |
+
import requests
|
| 67 |
+
|
| 68 |
+
USERNAME = "jcleee"
|
| 69 |
+
AGENT_CODE_URL = "https://huggingface.co/spaces/jcleee/First_agent_template/tree/main"
|
| 70 |
+
BASE_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 71 |
+
|
| 72 |
+
def load_questions():
|
| 73 |
+
return requests.get(f"{BASE_URL}/questions").json()
|
| 74 |
+
|
| 75 |
+
def run_agent_on_question(question_text):
|
| 76 |
+
output = agent.run(task=question_text, reset=True)
|
| 77 |
+
for step in output:
|
| 78 |
+
if hasattr(step, "final_answer"):
|
| 79 |
+
return step.final_answer
|
| 80 |
+
elif hasattr(step, "tool_calls"):
|
| 81 |
+
for call in step.tool_calls:
|
| 82 |
+
if call.name == "final_answer":
|
| 83 |
+
return call.arguments.get("answer")
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
questions = load_questions()
|
| 87 |
+
answers = []
|
| 88 |
+
|
| 89 |
+
for q in questions:
|
| 90 |
+
answer = run_agent_on_question(q["question"])
|
| 91 |
+
if answer is None:
|
| 92 |
+
answer = "null"
|
| 93 |
+
answers.append({"task_id": q["task_id"], "submitted_answer": str(answer)})
|
| 94 |
+
|
| 95 |
+
payload = {"username": USERNAME, "agent_code": AGENT_CODE_URL, "answers": answers}
|
| 96 |
+
response = requests.post(f"{BASE_URL}/submit", json=payload)
|
| 97 |
+
print("✅ Submission complete")
|
| 98 |
+
print(response.status_code, response.json())
|
| 99 |
+
|