File size: 966 Bytes
febc52d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)