Download test/test.py from CJR61/papi_cc: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/CJR61/papi_cc/resolve/a5ec00a6525a3ea20c112dfe4f265aa800b17ddf/test/test.py
- Command line
-
hf download hf://spaces/CJR61/papi_cc@a5ec00a6525a3ea20c112dfe4f265aa800b17ddf/test/test.py
-
curl -L -o test.py https://huggingface.co/spaces/CJR61/papi_cc/resolve/a5ec00a6525a3ea20c112dfe4f265aa800b17ddf/test/test.py
1.73 kB
| import requests | |
| import time | |
| import os | |
| BASE_URL = "https://cjr61-papi-cc.hf.space" | |
| API_KEY = "5175231e76de498f2a7455c19dc92a551b9b9c8a" | |
| HEADERS = {"X-API-Key": API_KEY} | |
| DATA_DIR = os.path.join(os.path.dirname(__file__), "data") | |
| # Expected results for validation | |
| EXPECTED = { | |
| "ec.JPG": "bacteria", | |
| "ped.JPG": "virus", | |
| "nr1.png": "None", | |
| "nr2.jpg": "None", | |
| "nr3.jpg": "None", | |
| "nr4.jpg": "None", | |
| "rw.jpg": "virus", | |
| } | |
| def test_predict(image_path): | |
| url = f"{BASE_URL}/predict/" | |
| t0 = time.time() | |
| with open(image_path, "rb") as f: | |
| response = requests.post(url, headers=HEADERS, files={"file": f}) | |
| elapsed = round(time.time() - t0, 2) | |
| return response, elapsed | |
| def run_all(): | |
| print(f"Target: {BASE_URL}\n{'='*55}") | |
| passed = failed = 0 | |
| for fname, expected in EXPECTED.items(): | |
| path = os.path.join(DATA_DIR, fname) | |
| if not os.path.exists(path): | |
| print(f" [SKIP] {fname} — file not found") | |
| continue | |
| resp, elapsed = test_predict(path) | |
| if resp.status_code != 200: | |
| print(f" [FAIL] {fname} — HTTP {resp.status_code} ({elapsed}s)") | |
| failed += 1 | |
| continue | |
| result = resp.json() | |
| cls = result.get("class", "?") | |
| prob = result.get("probability", "?") | |
| ok = cls == expected | |
| mark = "PASS" if ok else "FAIL" | |
| if ok: | |
| passed += 1 | |
| else: | |
| failed += 1 | |
| print(f" [{mark}] {fname:<12} got={cls:<10} prob={prob} expected={expected} ({elapsed}s)") | |
| print(f"{'='*55}") | |
| print(f" Result: {passed} passed, {failed} failed / {passed+failed} total") | |
| if __name__ == "__main__": | |
| run_all() | |