shrutikaP8497 commited on
Commit
9bbed17
Β·
verified Β·
1 Parent(s): 82ec8dc

Update submission.py

Browse files
Files changed (1) hide show
  1. submission.py +74 -79
submission.py CHANGED
@@ -1,79 +1,74 @@
1
- import requests
2
- import gradio as gr
3
- from agent import run_agent_on_question
4
- from utils import format_answer
5
- from retriever import retrieve_relevant_context
6
-
7
- API_BASE_URL = "https://agents-course-unit4-scoring.hf.space"
8
-
9
- def fetch_questions():
10
- """
11
- Retrieve all evaluation questions from the API.
12
- """
13
- response = requests.get(f"{API_BASE_URL}/questions")
14
- return response.json() if response.status_code == 200 else []
15
-
16
- def submit_answers_to_leaderboard(username, agent_code_url):
17
- """
18
- Runs the agent on all evaluation questions and submits answers.
19
- """
20
- questions = fetch_questions()
21
- print(f"Fetched {len(questions)} questions.")
22
-
23
- answers = []
24
-
25
- for q in questions:
26
- task_id = q["task_id"]
27
- question = q["question"]
28
-
29
- # Add RAG step (if needed)
30
- retrieved_context = retrieve_context(task_id)
31
-
32
- print(f"\nπŸ” Running agent on task: {task_id}")
33
- response = run_agent_on_question(question + "\n" + retrieved_context)
34
- formatted_answer = format_answer(response)
35
-
36
- print(f"Answer: {formatted_answer}")
37
- answers.append({
38
- "task_id": task_id,
39
- "submitted_answer": formatted_answer
40
- })
41
-
42
- # Prepare final submission payload
43
- submission = {
44
- "username": username,
45
- "agent_code": agent_code_url,
46
- "answers": answers
47
- }
48
-
49
- res = requests.post(f"{API_BASE_URL}/submit", json=submission)
50
- if res.status_code == 200:
51
- print("\nβœ… Submission Complete!")
52
- print("Result:", res.json())
53
- return res.json()
54
- else:
55
- print("\n❌ Submission Failed!")
56
- print("Status Code:", res.status_code)
57
- print("Response:", res.text)
58
- return None
59
-
60
- # Optional Gradio UI for easier submission
61
- with gr.Blocks() as demo:
62
- gr.Markdown("## πŸ€– GAIA Agent Submission")
63
-
64
- with gr.Row():
65
- username = gr.Textbox(label="Your Hugging Face Username")
66
- agent_code_url = gr.Textbox(label="Public URL to Your Hugging Face Space Code")
67
-
68
- submit_btn = gr.Button("Run Evaluation & Submit All Answers")
69
-
70
- output = gr.Textbox(label="Submission Result")
71
-
72
- submit_btn.click(
73
- fn=submit_answers_to_leaderboard,
74
- inputs=[username, agent_code_url],
75
- outputs=[output]
76
- )
77
-
78
- if __name__ == "__main__":
79
- demo.launch()
 
1
+ # submission.py
2
+
3
+ import requests
4
+ import gradio as gr
5
+ from agent import run_agent_on_question
6
+ from utils import format_answer
7
+
8
+ API_BASE_URL = "https://agents-course-unit4-scoring.hf.space"
9
+
10
+ def fetch_questions():
11
+ """
12
+ Retrieve all evaluation questions from the API.
13
+ """
14
+ response = requests.get(f"{API_BASE_URL}/questions")
15
+ return response.json() if response.status_code == 200 else []
16
+
17
+ def submit_answers_to_leaderboard(username, agent_code_url):
18
+ """
19
+ Runs the agent on all evaluation questions and submits answers.
20
+ """
21
+ questions = fetch_questions()
22
+ print(f"Fetched {len(questions)} questions.")
23
+
24
+ answers = []
25
+
26
+ for q in questions:
27
+ print(f"\nπŸ” Running agent on task: {q['task_id']}")
28
+ response = run_agent_on_question(q) # βœ… Pass full task dictionary
29
+ formatted_answer = format_answer(response)
30
+
31
+ print(f"Answer: {formatted_answer}")
32
+ answers.append({
33
+ "task_id": q["task_id"],
34
+ "submitted_answer": formatted_answer
35
+ })
36
+
37
+ # Prepare final submission payload
38
+ submission = {
39
+ "username": username,
40
+ "agent_code": agent_code_url,
41
+ "answers": answers
42
+ }
43
+
44
+ res = requests.post(f"{API_BASE_URL}/submit", json=submission)
45
+ if res.status_code == 200:
46
+ print("\nβœ… Submission Complete!")
47
+ print("Result:", res.json())
48
+ return res.json()
49
+ else:
50
+ print("\n❌ Submission Failed!")
51
+ print("Status Code:", res.status_code)
52
+ print("Response:", res.text)
53
+ return None
54
+
55
+ # Optional Gradio UI for easier submission
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown("## πŸ€– GAIA Agent Submission")
58
+
59
+ with gr.Row():
60
+ username = gr.Textbox(label="Your Hugging Face Username")
61
+ agent_code_url = gr.Textbox(label="Public URL to Your Hugging Face Space Code")
62
+
63
+ submit_btn = gr.Button("Run Evaluation & Submit All Answers")
64
+
65
+ output = gr.Textbox(label="Submission Result")
66
+
67
+ submit_btn.click(
68
+ fn=submit_answers_to_leaderboard,
69
+ inputs=[username, agent_code_url],
70
+ outputs=[output]
71
+ )
72
+
73
+ if __name__ == "__main__":
74
+ demo.launch()