Spaces:
Running

anycoder-536dd853 / index.html
Jepeto85's picture
Upload folder using huggingface_hub
08e47f1 verified
Raw History Blame Contribute Delete
18.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Submission System</title>
<!-- Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #6366f1;
--primary-hover: #4f46e5;
--success-color: #10b981;
--danger-color: #ef4444;
--bg-dark: #0f172a;
--bg-card: #1e293b;
--text-main: #f8fafc;
--text-muted: #94a3b8;
--border-color: #334155;
--shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-dark);
color: var(--text-main);
line-height: 1.6;
display: flex;
flex-direction: column;
min-height: 100vh;
}
/* Header & Footer */
header {
padding: 20px;
text-align: center;
border-bottom: 1px solid var(--border-color);
background: rgba(15, 23, 42, 0.95);
position: sticky;
top: 0;
z-index: 100;
backdrop-filter: blur(10px);
}
h1 {
font-size: 1.5rem;
font-weight: 700;
color: var(--primary-color);
}
.anycoder-link {
font-size: 0.8rem;
color: var(--text-muted);
margin-top: 5px;
display: inline-block;
text-decoration: none;
transition: color 0.3s;
}
.anycoder-link:hover {
color: var(--primary-color);
text-decoration: underline;
}
main {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 40px 20px;
}
/* Main Card */
.container {
background-color: var(--bg-card);
border-radius: 24px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
width: 100%;
max-width: 600px;
padding: 40px;
border: 1px solid var(--border-color);
transition: transform 0.3s ease;
}
.header-section {
text-align: center;
margin-bottom: 30px;
}
.header-section h2 {
font-size: 2rem;
margin-bottom: 10px;
}
.header-section p {
color: var(--text-muted);
}
/* Drag & Drop Zone */
.upload-zone {
border: 2px dashed var(--border-color);
border-radius: 16px;
padding: 60px 20px;
text-align: center;
transition: all 0.4s ease;
cursor: pointer;
background: rgba(255,255,255,0.02);
position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
border-color: var(--primary-color);
background: rgba(99, 102, 241, 0.1);
transform: scale(1.02);
box-shadow: var(--shadow-glow);
}
.upload-zone i {
font-size: 4rem;
color: var(--text-muted);
margin-bottom: 20px;
transition: color 0.3s;
}
.upload-zone:hover i, .upload-zone.drag-over i {
color: var(--primary-color);
}
.upload-text {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 10px;
display: block;
}
.upload-subtext {
font-size: 0.9rem;
color: var(--text-muted);
}
.file-input {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
cursor: pointer;
}
/* File List & Status */
.file-details {
margin-top: 30px;
display: none; /* Hidden by default */
background: rgba(0,0,0,0.3);
padding: 20px;
border-radius: 12px;
border: 1px solid var(--border-color);
}
.file-item {
display: flex;
align-items: center;
gap: 15px;
padding: 15px;
background: rgba(30, 41, 59, 0.8);
border-radius: 8px;
margin-bottom: 15px;
animation: fadeIn 0.5s ease;
}
.file-icon {
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background: #1e293b;
border-radius: 10px;
color: var(--primary-color);
font-size: 1.5rem;
flex-shrink: 0;
}
.file-info {
flex: 1;
overflow: hidden;
}
.file-name {
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
color: var(--text-main);
}
.file-meta {
font-size: 0.8rem;
color: var(--text-muted);
}
.status-badge {
padding: 5px 12px;
border-radius: 20px;
font-size: 0.8rem;
font-weight: 600;
text-transform: uppercase;
}
.status-valid {
background: rgba(16, 185, 129, 0.2);
color: var(--success-color);
border: 1px solid var(--success-color);
}
.status-invalid {
background: rgba(239, 68, 68, 0.2);
color: var(--danger-color);
border: 1px solid var(--danger-color);
}
/* Action Buttons */
.actions {
margin-top: 30px;
display: flex;
gap: 15px;
justify-content: center;
}
button {
padding: 12px 32px;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 10px;
}
.btn-primary {
background-color: var(--primary-color);
color: white;
box-shadow: var(--shadow-glow);
border: none;
}
.btn-primary:hover {
background-color: var(--primary-hover);
transform: translateY(-2px);
box-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
}
.btn-primary:disabled {
background-color: var(--border-color);
cursor: not-allowed;
box-shadow: none;
transform: none;
}
.btn-secondary {
background-color: transparent;
color: var(--text-muted);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background-color: rgba(255,255,255,0.05);
color: var(--text-main);
}
/* Modal for Results */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease;
backdrop-filter: blur(5px);
}
.modal-overlay.active {
opacity: 1;
pointer-events: all;
}
.modal-content {
background: var(--bg-card);
padding: 40px;
border-radius: 24px;
text-align: center;
max-width: 500px;
width: 90%;
border: 1px solid var(--border-color);
transform: translateY(20px);
transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content {
transform: translateY(0);
}
.modal-icon {
font-size: 4rem;
margin-bottom: 20px;
display: block;
}
.modal-title {
font-size: 2rem;
margin-bottom: 15px;
}
.modal-body {
color: var(--text-muted);
margin-bottom: 30px;
line-height: 1.6;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* Responsive */
@media (max-width: 600px) {
.container { padding: 20px; }
.header-section h2 { font-size: 1.5rem; }
.actions { flex-direction: column; }
button { width: 100%; justify-content: center; }
}
</style>
</head>
<body>
<header>
<h1><i class="fa-solid fa-cloud-arrow-up"></i> SecureSubmit</h1>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">
Built with anycoder
</a>
</header>
<main>
<div class="container">
<div class="header-section">
<h2>Upload your project</h2>
<p>Support for ZIP, PDF, and Image files (Max 25MB)</p>
</div>
<!-- Drag and Drop Zone -->
<div class="upload-zone" id="dropZone">
<i class="fa-solid fa-file-zipper"></i>
<span class="upload-text">Drag & Drop files here</span>
<span class="upload-subtext">or click to browse from your computer</span>
<input type="file" id="fileInput" accept=".zip,application/zip,application/x-zip-compressed">
</div>
<!-- File Details Section -->
<div class="file-details" id="fileDetails">
<div class="file-item">
<div class="file-icon">
<i class="fa-solid fa-file-archive"></i>
</div>
<div class="file-info">
<span class="file-name" id="fileName">project.zip</span>
<span class="file-meta" id="fileSize">2.4 MB</span>
</div>
<div id="fileStatusBadge" class="status-badge status-valid">
<i class="fa-solid fa-check-circle"></i> Valid Format
</div>
</div>
</div>
<div class="actions">
<button class="btn-secondary" id="clearBtn">
<i class="fa-solid fa-xmark"></i> Clear
</button>
<button class="btn-primary" id="submitBtn" disabled>
<i class="fa-solid fa-paper-plane"></i> Submit File
</button>
</div>
</div>
</main>
<!-- Result Modal -->
<div class="modal-overlay" id="resultModal">
<div class="modal-content">
<span class="modal-icon" id="modalIcon"></span>
<h2 class="modal-title" id="modalTitle"></h2>
<p class="modal-body" id="modalBody"></p>
<button class="btn-primary" onclick="closeModal()">Close</button>
</div>
</div>
<footer style="text-align: center; padding: 20px; color: var(--text-muted); font-size: 0.8rem; border-top: 1px solid var(--border-color);">
&copy; 2023 SecureSubmit System. Client-side validation enabled.
</footer>
<script>
// DOM Elements
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const fileDetails = document.getElementById('fileDetails');
const fileNameEl = document.getElementById('fileName');
const fileSizeEl = document.getElementById('fileSize');
const fileStatusBadge = document.getElementById('fileStatusBadge');
const submitBtn = document.getElementById('submitBtn');
const clearBtn = document.getElementById('clearBtn');
const resultModal = document.getElementById('resultModal');
let currentFile = null;
// Helper: Format bytes to human readable
const formatBytes = (bytes, decimals = 2) => {
if (!+bytes) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
};
// Helper: Check if file is a ZIP
const isZipFile = (file) => {
const validMimeTypes = ['application/zip', 'application/x-zip-compressed'];
// Common MIME types for ZIP
const isMime = validMimeTypes.includes(file.type);
// Fallback for extension check if MIME type is missing (common on some OS)
const isExtension = file.name.toLowerCase().endsWith('.zip');
return isMime || isExtension;
};
// Event: Drag & Drop Over
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('drag-over');
});
// Event: Drag & Drop Leave
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('drag-over');
});
// Event: Drop
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('drag-over');
if (e.dataTransfer.files.length) {
handleFile(e.dataTransfer.files[0]);
}
});
// Event: Click to Upload
fileInput.addEventListener('change', (e) => {
if (e.target.files.length) {
handleFile(e.target.files[0]);
}
});
// Logic: Handle File Selection
function handleFile(file) {
currentFile = file;
// Update UI
fileNameEl.textContent = file.name;
fileSizeEl.textContent = formatBytes(file.size);
// Validation Logic
if (isZipFile(file)) {
fileStatusBadge.className = 'status-badge status-valid';
fileStatusBadge.innerHTML = '<i class="fa-solid fa-check-circle"></i> Valid (ZIP)';
submitBtn.disabled = false;
submitBtn.innerHTML = '<i class="fa-solid fa-check"></i> Ready to Submit';
submitBtn.style.backgroundColor = 'var(--success-color)';
submitBtn.style.boxShadow = '0 0 20px rgba(16, 185, 129, 0.3)';
} else {
fileStatusBadge.className = 'status-badge status-invalid';
fileStatusBadge.innerHTML = '<i class="fa-solid fa-circle-xmark"></i> Invalid Format';
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fa-solid fa-ban"></i> Select ZIP File';
submitBtn.style.backgroundColor = 'var(--border-color)';
submitBtn.style.boxShadow = 'none';
// Visual feedback on drop zone
dropZone.style.borderColor = 'var(--danger-color)';
setTimeout(() => {
dropZone.style.borderColor = 'var(--border-color)';
}, 3000);
}
// Show details
fileDetails.style.display = 'block';
}
// Event: Clear
clearBtn.addEventListener('click', () => {
currentFile = null;
fileInput.value = ''; // Reset input
fileDetails.style.display = 'none';
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fa-solid fa-paper-plane"></i> Submit File';
submitBtn.style.backgroundColor = ''; // Reset to CSS default
submitBtn.style.boxShadow = '';
dropZone.classList.remove('drag-over');
});
// Event: Submit
submitBtn.addEventListener('click', () => {
if (!currentFile) return;
// Simulate Upload Process
const originalBtnText = submitBtn.innerHTML;
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Processing...';
setTimeout(() => {
// Success Simulation
submitBtn.innerHTML = originalBtnText;
showModal(true, "Submission Successful!", `Your file <strong>${currentFile.name}</strong> has been successfully uploaded and is being processed. You will receive an email confirmation shortly.`);
}, 1500);
});
// Modal Logic
function showModal(isSuccess, title, body) {
const icon = document.getElementById('modalIcon');
const modalTitle = document.getElementById('modalTitle');
const modalBody = document.getElementById('modalBody');
if (isSuccess) {
icon.innerHTML = '<i class="fa-solid fa-circle-check" style="color: var(--success-color);"></i>';
modalTitle.style.color = 'var(--success-color)';
} else {
icon.innerHTML = '<i class="fa-solid fa-circle-xmark" style="color: var(--danger-color);"></i>';
modalTitle.style.color = 'var(--danger-color)';
}
modalTitle.textContent = title;
modalBody.innerHTML = body;
resultModal.classList.add('active');
}
window.closeModal = function() {
resultModal.classList.remove('active');
// Reset button state if modal closes after success
if(submitBtn.innerHTML.includes('Processing')) {
submitBtn.disabled = false;
submitBtn.innerHTML = '<i class="fa-solid fa-check"></i> Ready to Submit';
}
};
// Close modal on outside click
resultModal.addEventListener('click', (e) => {
if (e.target === resultModal) {
closeModal();
}
});
// Initialize state
submitBtn.disabled = true;
fileDetails.style.display = 'none';
</script>
</body>
</html>