Spaces:
Sleeping
Sleeping
Delete submit.py
Browse files
submit.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import os
|
| 3 |
-
from app import agent # 👈 imports your agent
|
| 4 |
-
|
| 5 |
-
USERNAME = "jcleee"
|
| 6 |
-
AGENT_CODE_URL = "https://huggingface.co/spaces/jcleee/First_agent_template/tree/main"
|
| 7 |
-
BASE_API = "https://agents-course-unit4-scoring.hf.space"
|
| 8 |
-
|
| 9 |
-
def download_files(task_id, filenames):
|
| 10 |
-
for fname in filenames:
|
| 11 |
-
url = f"{BASE_API}/files/{task_id}"
|
| 12 |
-
response = requests.get(url)
|
| 13 |
-
os.makedirs("downloads", exist_ok=True)
|
| 14 |
-
with open(f"downloads/{fname}", "wb") as f:
|
| 15 |
-
f.write(response.content)
|
| 16 |
-
|
| 17 |
-
def load_questions():
|
| 18 |
-
r = requests.get(f"{BASE_API}/questions")
|
| 19 |
-
r.raise_for_status()
|
| 20 |
-
return r.json()
|
| 21 |
-
|
| 22 |
-
def run_agent(question_text, additional_args=None):
|
| 23 |
-
output = agent.run(task=question_text, reset=True, additional_args=additional_args)
|
| 24 |
-
for step in output:
|
| 25 |
-
if hasattr(step, "final_answer"):
|
| 26 |
-
return step.final_answer
|
| 27 |
-
elif hasattr(step, "tool_calls"):
|
| 28 |
-
for call in step.tool_calls:
|
| 29 |
-
if call.name == "final_answer":
|
| 30 |
-
return call.arguments.get("answer")
|
| 31 |
-
return None
|
| 32 |
-
|
| 33 |
-
def main():
|
| 34 |
-
questions = load_questions()
|
| 35 |
-
answers = []
|
| 36 |
-
|
| 37 |
-
for q in questions:
|
| 38 |
-
print(f"Running task: {q['task_id']}")
|
| 39 |
-
if q["files"]:
|
| 40 |
-
download_files(q["task_id"], q["files"])
|
| 41 |
-
|
| 42 |
-
answer = run_agent(q["question"])
|
| 43 |
-
print("Answer:", answer)
|
| 44 |
-
answers.append({"task_id": q["task_id"], "submitted_answer": str(answer)})
|
| 45 |
-
|
| 46 |
-
payload = {
|
| 47 |
-
"username": USERNAME,
|
| 48 |
-
"agent_code": AGENT_CODE_URL,
|
| 49 |
-
"answers": answers
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
r = requests.post(f"{BASE_API}/submit", json=payload)
|
| 53 |
-
print("Submission status:", r.status_code)
|
| 54 |
-
print(r.json())
|
| 55 |
-
|
| 56 |
-
if __name__ == "__main__":
|
| 57 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|