Download test_hf_api.py from Yashk0618/projectY_Classifier_Regressor: direct link, hf CLI and curl.
- Browser
- Download file 966 Bytes
-
https://huggingface.co/spaces/Yashk0618/projectY_Classifier_Regressor/resolve/main/test_hf_api.py
- Command line
-
hf download hf://spaces/Yashk0618/projectY_Classifier_Regressor/test_hf_api.py
-
curl -L -o test_hf_api.py https://huggingface.co/spaces/Yashk0618/projectY_Classifier_Regressor/resolve/main/test_hf_api.py
966 Bytes
| import requests | |
| import random | |
| BASE = "https://yashk0618-projecty-classifier-regressor.hf.space" | |
| def predict_wastage(features): | |
| url = f"{BASE}/predict/wastage" | |
| payload = {"features": features} | |
| r = requests.post(url, json=payload) | |
| if not r.ok: | |
| raise Exception(f"HF error {r.status_code}: {r.text}") | |
| return r.json() | |
| def predict_stockout(features): | |
| url = f"{BASE}/predict/stockout" | |
| payload = {"features": features} | |
| r = requests.post(url, json=payload) | |
| if not r.ok: | |
| raise Exception(f"HF error {r.status_code}: {r.text}") | |
| return r.json() | |
| if __name__ == "__main__": | |
| # 20 random feature values (match your JS test) | |
| features = [round(random.random() * 10, 2) for _ in range(20)] | |
| print("Features:", features) | |
| wastage_result = predict_wastage(features) | |
| stockout_result = predict_stockout(features) | |
| print("Wastage result:", wastage_result) | |
| print("Stockout result:", stockout_result) | |