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 to Sketch</title> | |
<style> | |
/* Style to make the image smaller */ | |
#result img { | |
max-width: 100%; | |
height: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Image to Sketch</h1> | |
<form action="/upload/" method="post" enctype="multipart/form-data"> | |
<input type="file" name="file"> | |
<button type="submit">Upload</button> | |
</form> | |
<div id="result"></div> | |
<script> | |
async function uploadFile() { | |
const formData = new FormData(); | |
const fileInput = document.querySelector('input[type="file"]'); | |
formData.append('file', fileInput.files[0]); | |
const response = await fetch('/upload/', { | |
method: 'POST', | |
body: formData | |
}); | |
const data = await response.json(); | |
const sketchImage = document.createElement('img'); | |
sketchImage.src = data.sketch_image_base64; | |
// Clear previous result | |
document.getElementById('result').innerHTML = ''; | |
// Append new image | |
document.getElementById('result').appendChild(sketchImage); | |
} | |
document.querySelector('form').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
uploadFile(); | |
}); | |
</script> | |
</body> | |
</html> | |