Mohamed-Riyaz's picture
Upload 6 files
fd4d5da verified
Raw History Blame Contribute Delete
7.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OCR Text Extractor</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
padding: 50px;
max-width: 600px;
width: 100%;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
text-align: center;
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 2.5em;
}
.subtitle {
color: #666;
margin-bottom: 30px;
font-size: 1em;
}
.upload-area {
border: 3px dashed #ddd;
border-radius: 15px;
padding: 40px 20px;
transition: all 0.3s ease;
cursor: pointer;
background: #fafafa;
}
.upload-area:hover {
border-color: #667eea;
background: #f0f2ff;
}
.upload-area.dragover {
border-color: #667eea;
background: #e8ebff;
transform: scale(1.02);
}
.upload-icon {
font-size: 3em;
margin-bottom: 15px;
}
.upload-text {
color: #666;
font-size: 1.1em;
}
.upload-text strong {
color: #667eea;
}
#fileInput {
display: none;
}
#previewContainer {
margin-top: 20px;
display: none;
}
#imagePreview {
max-width: 100%;
max-height: 300px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.file-info {
margin-top: 10px;
color: #666;
font-size: 0.9em;
}
.upload-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 15px 50px;
font-size: 1.1em;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
margin-top: 20px;
font-weight: 600;
letter-spacing: 0.5px;
}
.upload-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}
.upload-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.loading {
display: none;
margin-top: 20px;
padding: 15px;
background: #f0f2ff;
border-radius: 10px;
color: #667eea;
}
.loading.active {
display: block;
}
.spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid #ddd;
border-radius: 50%;
border-top-color: #667eea;
animation: spin 1s ease-in-out infinite;
margin-right: 10px;
vertical-align: middle;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 600px) {
.container {
padding: 30px 20px;
}
h1 {
font-size: 2em;
}
}
</style>
</head>
<body>
<div class="container">
<h1>๐Ÿ“ OCR Text Extractor</h1>
<p class="subtitle">Upload an image and extract text from it instantly</p>
<form action="/upload" method="POST" enctype="multipart/form-data" id="uploadForm">
<div class="upload-area" id="dropZone">
<div class="upload-icon">๐Ÿ–ผ๏ธ</div>
<div class="upload-text">
<strong>Click to browse</strong> or drag & drop your image here
</div>
<div class="file-info">Supports: JPG, PNG, GIF, BMP</div>
<input type="file" name="image" id="fileInput" accept="image/*">
</div>
<div id="previewContainer">
<img id="imagePreview" src="#" alt="Preview">
<div class="file-info" id="fileName"></div>
</div>
<button type="submit" class="upload-btn" id="submitBtn">Extract Text โœจ</button>
</form>
<div class="loading" id="loadingIndicator">
<span class="spinner"></span>
Processing your image...
</div>
</div>
<script>
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const previewContainer = document.getElementById('previewContainer');
const imagePreview = document.getElementById('imagePreview');
const fileName = document.getElementById('fileName');
const submitBtn = document.getElementById('submitBtn');
const loadingIndicator = document.getElementById('loadingIndicator');
const form = document.getElementById('uploadForm');
// Click to upload
dropZone.addEventListener('click', () => {
fileInput.click();
});
// File selected
fileInput.addEventListener('change', (e) => {
handleFile(e.target.files[0]);
});
// Drag and drop
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const file = e.dataTransfer.files[0];
handleFile(file);
fileInput.files = e.dataTransfer.files;
});
function handleFile(file) {
if (file && file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onload = (e) => {
imagePreview.src = e.target.result;
previewContainer.style.display = 'block';
fileName.textContent = `๐Ÿ“Ž ${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`;
dropZone.style.display = 'none';
};
reader.readAsDataURL(file);
} else {
alert('Please upload a valid image file.');
fileInput.value = '';
}
}
// Show loading on submit
form.addEventListener('submit', () => {
if (fileInput.files.length > 0) {
submitBtn.disabled = true;
loadingIndicator.classList.add('active');
submitBtn.textContent = 'Processing...';
}
});
</script>
</body>
</html>