jcleee commited on
Commit
9ba52c8
·
verified ·
1 Parent(s): 3378301

Delete submit.py

Browse files
Files changed (1) hide show
  1. submit.py +0 -99
submit.py DELETED
@@ -1,99 +0,0 @@
1
- import requests
2
- import os
3
-
4
- # ✅ Your Hugging Face credentials
5
- USERNAME = "jcleee"
6
- AGENT_CODE_URL = "https://huggingface.co/spaces/jcleee/First_agent_template/tree/main"
7
- BASE_URL = "https://agents-course-unit4-scoring.hf.space"
8
-
9
- def download_files(task_id, filenames):
10
- for fname in filenames:
11
- url = f"{BASE_URL}/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
- response = requests.get(f"{BASE_URL}/questions")
19
- response.raise_for_status()
20
- return response.json()
21
-
22
- def run_agent_on_question(question_text, agent):
23
- output = agent.run(task=question_text, reset=True)
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 submit_answers(agent):
34
- questions = load_questions()
35
- answers = []
36
-
37
- for q in questions:
38
- print(f"Running task: {q['task_id']}")
39
-
40
- if q["files"]:
41
- download_files(q["task_id"], q["files"])
42
-
43
- answer = run_agent_on_question(q["question"], agent)
44
- print("Answer:", answer)
45
-
46
- answers.append({
47
- "task_id": q["task_id"],
48
- "submitted_answer": str(answer or "null")
49
- })
50
-
51
- payload = {
52
- "username": USERNAME,
53
- "agent_code": AGENT_CODE_URL,
54
- "answers": answers
55
- }
56
-
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
-