Spaces:
Runtime error
Runtime error
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Image Classification</title> | |
| <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.9.0/dist/tf.min.js"></script> | |
| </head> | |
| <body> | |
| <h1>Image Classification</h1> | |
| <input type="file" id="imageInput" accept="image/*"> | |
| <img id="inputImage" src="#" alt="Input Image" style="max-width: 300px; max-height: 300px;"> | |
| <button onclick="classifyImage()">Classify</button> | |
| <div id="output"></div> | |
| <script> | |
| async function classifyImage() { | |
| const file = document.getElementById('imageInput').files[0]; | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| const response = await fetch('http://localhost:5000/classify', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| const result = await response.json(); | |
| const outputElement = document.getElementById('output'); | |
| outputElement.innerHTML = '<h2>Predictions:</h2>'; | |
| result.predictions.forEach(prediction => { | |
| outputElement.innerHTML += `<p>${prediction.className}: ${prediction.probability.toFixed(4)}</p>`; | |
| }); | |
| } | |
| document.getElementById('imageInput').addEventListener('change', function(event) { | |
| const file = event.target.files[0]; | |
| const imageElement = document.getElementById('inputImage'); | |
| imageElement.src = URL.createObjectURL(file); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |