nexus-uploader / index.html
ChandimaPrabath's picture
styles
ebb1c1c
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload with Progress</title>
<style>
/* General dark theme */
* {
box-sizing: border-box;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
body {
background-color: #121212;
color: #e0e0e0;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px;
min-height: 100vh;
}
h2 {
font-size: 1.8rem;
color: #ffffff;
margin-bottom: 20px;
}
form {
background: #1e1e1e;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.3);
width: 100%;
max-width: 400px;
}
label {
color: #bdbdbd;
font-weight: bold;
display: block;
margin-top: 15px;
}
input[type="password"],
input[type="text"],
input[type="file"] {
background: #333;
color: #e0e0e0;
border: none;
border-radius: 4px;
padding: 10px;
width: 100%;
margin-top: 5px;
outline: none;
transition: border 0.3s ease;
}
input[type="password"]:focus,
input[type="text"]:focus,
input[type="file"]:focus {
border: 1px solid #4f8cff;
}
button {
background-color: #4f8cff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 20px;
width: 100%;
transition: background 0.3s;
font-weight: bold;
}
button:hover {
background-color: #3571db;
}
/* Progress Section */
#progress {
margin-top: 20px;
width: 100%;
max-width: 400px;
text-align: left;
}
#progress h3 {
font-size: 1.4rem;
margin-bottom: 10px;
}
pre {
background: #212121;
color: #bdbdbd;
padding: 12px;
border-radius: 6px;
font-size: 0.9rem;
overflow: auto;
margin-top: 5px;
}
</style>
</head>
<body>
<h2>Upload Files to Hugging Face Repository</h2>
<form id="uploadForm" enctype="multipart/form-data">
<label for="access_key">Access Key:</label>
<input type="password" id="access_key" name="access_key" required>
<label for="destination_folder">Destination Folder:</label>
<input type="text" id="destination_folder" name="destination_folder" required>
<label for="files">Select Files:</label>
<input type="file" id="files" name="files" multiple required>
<button type="submit">Upload Files</button>
</form>
<div id="progress">
<h3>Upload Progress</h3>
<pre id="clientProgressText">Client to Server: No upload in progress...</pre>
<pre id="serverProgressText">Server to Storage: No upload in progress...</pre>
</div>
<script>
document.getElementById("uploadForm").onsubmit = async function(event) {
event.preventDefault();
const formData = new FormData(this);
const clientProgressText = document.getElementById("clientProgressText");
const serverProgressText = document.getElementById("serverProgressText");
// Reset progress text
clientProgressText.textContent = "Client to Server: Starting upload...";
serverProgressText.textContent = "Server to Storage: No upload in progress...";
// Create XMLHttpRequest to track client-to-server upload progress
const xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
// Add a progress event listener to track the upload to the server
xhr.upload.onprogress = function(event) {
if (event.lengthComputable) {
const percentComplete = (event.loaded / event.total) * 100;
clientProgressText.textContent = `Client to Server: ${percentComplete.toFixed(2)}% uploaded`;
}
};
// Handle server response
xhr.onload = async function() {
if (xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const statusId = result.status_id;
// Start polling for server-to-storage progress
serverProgressText.textContent = "Server to Storage: Starting upload...";
const intervalId = setInterval(async () => {
const progressResponse = await fetch(`/progress/${statusId}`);
if (progressResponse.ok) {
const progressResult = await progressResponse.json();
serverProgressText.textContent = progressResult.progress.join("");
} else {
clearInterval(intervalId);
serverProgressText.textContent += "\nServer to Storage: Upload completed or status not found.";
}
}, 2000);
} else {
clientProgressText.textContent = "Client to Server: Upload failed.";
}
};
// Send the request
xhr.send(formData);
};
</script>
</body>
</html>