alfulanny commited on
Commit
6fe09f5
·
verified ·
1 Parent(s): 15893ec

Update evaluation_client.py

Browse files
Files changed (1) hide show
  1. evaluation_client.py +46 -0
evaluation_client.py CHANGED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+
3
+ Implements: GET /questions, GET /random-question, GET /files/{task_id}, POST /submit
4
+
5
+ Base URL: https://agents-course-unit4-scoring.hf.space
6
+ """
7
+ from typing import Any, Dict, List, Optional
8
+ import requests
9
+
10
+
11
+ class ScoringAPIClient:
12
+ def __init__(self, base_url: str = "https://agents-course-unit4-scoring.hf.space"):
13
+ self.base_url = base_url.rstrip("/")
14
+
15
+ def _url(self, path: str) -> str:
16
+ return f"{self.base_url}{path}"
17
+
18
+ def get_questions(self) -> List[Dict[str, Any]]:
19
+ resp = requests.get(self._url("/questions"))
20
+ resp.raise_for_status()
21
+ return resp.json()
22
+
23
+ def get_random_question(self) -> Dict[str, Any]:
24
+ resp = requests.get(self._url("/random-question"))
25
+ resp.raise_for_status()
26
+ return resp.json()
27
+
28
+ def download_file(self, task_id: int, dest_path: str) -> None:
29
+ resp = requests.get(self._url(f"/files/{task_id}"), stream=True)
30
+ resp.raise_for_status()
31
+ with open(dest_path, "wb") as f:
32
+ for chunk in resp.iter_content(chunk_size=8192):
33
+ if chunk:
34
+ f.write(chunk)
35
+
36
+ def submit(self, username: str, agent_code: str, answers: List[Dict[str, Any]]) -> Dict[str, Any]:
37
+ payload = {"username": username, "agent_code": agent_code, "answers": answers}
38
+ resp = requests.post(self._url("/submit"), json=payload)
39
+ resp.raise_for_status()
40
+ return resp.json()
41
+
42
+
43
+ if __name__ == "__main__":
44
+ c = ScoringAPIClient()
45
+ qs = c.get_questions()
46
+ print(f"Loaded {len(qs)} questions")