Spaces:
Sleeping
Sleeping
Download test_api.py from mjpsm/activity-instruction-api: direct link, hf CLI and curl.
- Browser
- Download file 911 Bytes
-
https://huggingface.co/spaces/mjpsm/activity-instruction-api/resolve/main/test_api.py
- Command line
-
hf download hf://spaces/mjpsm/activity-instruction-api/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/mjpsm/activity-instruction-api/resolve/main/test_api.py
911 Bytes
| import json | |
| import os | |
| from pathlib import Path | |
| import requests | |
| BASE_URL = os.getenv("INSTRUCTION_API_URL", "http://localhost:7860").rstrip("/") | |
| headers = {} | |
| if os.getenv("API_KEY"): | |
| headers["X-API-Key"] = os.environ["API_KEY"] | |
| payload = json.loads(Path(__file__).with_name("example_request.json").read_text(encoding="utf-8")) | |
| for endpoint in ["/health", "/model"]: | |
| response = requests.get(f"{BASE_URL}{endpoint}", timeout=30) | |
| print(endpoint, response.status_code) | |
| print(json.dumps(response.json(), indent=2, ensure_ascii=False)) | |
| response.raise_for_status() | |
| response = requests.post(f"{BASE_URL}/generate", json=payload, headers=headers, timeout=360) | |
| print("/generate", response.status_code) | |
| print(json.dumps(response.json(), indent=2, ensure_ascii=False)) | |
| response.raise_for_status() | |
| assert 1 <= len(response.json()["output"]["instructions"]) <= 5 | |
| print("Instruction API test passed.") | |