koala2 / app.html
root
Initial commit
f3adb3d
raw
history blame
3.41 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gradio Video Upload with Progress</title>
<style>
#progress-container {
width: 100%;
background-color: #f3f3f3;
border: 1px solid #ccc;
margin-top: 10px;
display: none;
}
#progress-bar {
width: 0%;
height: 20px;
background-color: #4caf50;
text-align: center;
color: white;
line-height: 20px;
transition: width 0.3s;
}
pre {
background: #f3f3f3;
padding: 10px;
border: 1px solid #ccc;
overflow-x: auto;
white-space: pre-wrap;
margin-top: 10px;
}
</style>
</head>
<body>
<h1>Upload Video and Process via Gradio API</h1>
<!-- Formulář pro nahrání videa -->
<form id="uploadForm" enctype="multipart/form-data">
<label for="video">Choose a video file:</label>
<input type="file" id="video" name="video" accept="video/*" required>
<button type="submit">Upload and Process</button>
</form>
<!-- Progress bar -->
<div id="progress-container">
<div id="progress-bar">0%</div>
</div>
<!-- Debug výpis -->
<h2>Debug Output:</h2>
<pre id="debug">Waiting for upload...</pre>
<script>
document.getElementById('uploadForm').addEventListener('submit', async (event) => {
event.preventDefault(); // Zabrání obnovení stránky
const fileInput = document.getElementById('video');
const file = fileInput.files[0];
const debugOutput = document.getElementById('debug');
const progressBar = document.getElementById('progress-bar');
const progressContainer = document.getElementById('progress-container');
if (!file) {
alert('Please select a video file to upload.');
return;
}
debugOutput.textContent = "Starting upload...\n";
progressContainer.style.display = "block";
const formData = new FormData();
formData.append('data', file);
const apiUrl = "http://127.0.0.1:7860/api/predict/";
try {
const xhr = new XMLHttpRequest();
xhr.open("POST", apiUrl, true);
// Aktualizace progress baru
xhr.upload.addEventListener("progress", (event) => {
if (event.lengthComputable) {
const percentComplete = Math.round((event.loaded / event.total) * 100);
progressBar.style.width = percentComplete + "%";
progressBar.textContent = percentComplete + "%";
}
});
// Zpracování odpovědi
xhr.onload = function () {
if (xhr.status === 200) {
debugOutput.textContent += "Upload complete! Server response:\n" + xhr.responseText;
progressBar.style.width = "100%";
progressBar.textContent = "Done";
} else {
debugOutput.textContent += `Error: ${xhr.statusText}\nServer response:\n${xhr.responseText}`;
}
};
xhr.onerror = function () {
debugOutput.textContent += "Error during the request.";
};
xhr.send(formData);
debugOutput.textContent += "File is being uploaded...\n";
} catch (error) {
debugOutput.textContent += `Unexpected error: ${error.message}`;
console.error("Error:", error);
}
});
</script>
</body>
</html>