|
|
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__": |
|
|
|
|
|
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) |
|
|
|