| <!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(); |
| out.textContent = `POST ${path}\nStatus: ${res.status}\n\n${text}`; |
| } catch (e) { |
| out.textContent = "Error:\n" + e; |
| } |
| } |
| </script> |
| </body> |
| </html> |
|
|