File size: 2,903 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>ProjectY API Tester</title>
    <style>
      body { font-family: Arial, sans-serif; padding: 20px; max-width: 700px; }
      input { width: 100%; padding: 10px; font-size: 14px; }
      button { padding: 10px 14px; margin-top: 10px; margin-right: 8px; cursor: pointer; }
      pre { background: #111; color: #0f0; padding: 12px; border-radius: 8px; overflow:auto; }
      .row { margin: 12px 0; }
    </style>
  </head>
  <body>
    <h2>ProjectY Hugging Face API Tester</h2>

    <div class="row">
      <div><b>API Base URL</b></div>
      <input id="baseUrl" value="https://Yashk0618-projecty-classifier-regressor.hf.space" />
      <small>Leave this as-is unless your Space URL is different.</small>
    </div>

    <div class="row">
      <div><b>Features (comma-separated numbers)</b></div>
      <input id="features" value="1,2,3,4,5" />
      <small>Important: the count must match what your model expects.</small>
    </div>

    <div class="row">
      <button onclick="testHealth()">Test GET /</button>
      <button onclick="predictWastage()">POST /predict/wastage</button>
      <button onclick="predictStockout()">POST /predict/stockout</button>
    </div>

    <h3>Result</h3>
    <pre id="out">Click a button to test…</pre>

    <script>
      function parseFeatures() {
        const raw = document.getElementById("features").value.trim();
        if (!raw) return [];
        return raw.split(",").map(x => Number(x.trim()));
      }

      async function testHealth() {
        const base = document.getElementById("baseUrl").value.trim();
        const out = document.getElementById("out");
        out.textContent = "Loading...";
        try {
          const res = await fetch(`${base}/`);
          const text = await res.text();
          out.textContent = `Status: ${res.status}\n\n${text}`;
        } catch (e) {
          out.textContent = "Error:\n" + e;
        }
      }

      async function predictWastage() {
        await postPredict("/predict/wastage");
      }

      async function predictStockout() {
        await postPredict("/predict/stockout");
      }

      async function postPredict(path) {
        const base = document.getElementById("baseUrl").value.trim();
        const feats = parseFeatures();
        const out = document.getElementById("out");
        out.textContent = "Loading...";
        try {
          const res = await fetch(`${base}${path}`, {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ features: feats })
          });

          const text = await res.text(); // handles JSON or error text
          out.textContent = `POST ${path}\nStatus: ${res.status}\n\n${text}`;
        } catch (e) {
          out.textContent = "Error:\n" + e;
        }
      }
    </script>
  </body>
</html>