Files
wifi-densepose/vendor/ruvector/examples/scipix/examples/wasm_demo.html

443 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ruvector-scipix Browser Demo</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.subtitle {
font-size: 1.1em;
opacity: 0.9;
}
.main-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
padding: 30px;
}
.upload-section {
display: flex;
flex-direction: column;
gap: 20px;
}
.upload-area {
border: 3px dashed #667eea;
border-radius: 15px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
background: #f8f9ff;
}
.upload-area:hover {
border-color: #764ba2;
background: #f0f2ff;
transform: translateY(-2px);
}
.upload-area.dragover {
border-color: #764ba2;
background: #e8ebff;
}
.upload-icon {
font-size: 3em;
margin-bottom: 15px;
}
.file-input {
display: none;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 15px 30px;
border-radius: 10px;
font-size: 1em;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.preview-container {
background: #f8f9ff;
border-radius: 15px;
padding: 20px;
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
#preview {
max-width: 100%;
max-height: 400px;
border-radius: 10px;
}
.results-section {
display: flex;
flex-direction: column;
gap: 20px;
}
.result-box {
background: #f8f9ff;
border-radius: 15px;
padding: 20px;
min-height: 150px;
}
.result-box h3 {
color: #667eea;
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 10px;
}
.result-content {
background: white;
padding: 15px;
border-radius: 10px;
font-family: 'Courier New', monospace;
white-space: pre-wrap;
word-break: break-word;
max-height: 300px;
overflow-y: auto;
}
.confidence-bar {
background: #e0e0e0;
height: 30px;
border-radius: 15px;
overflow: hidden;
position: relative;
}
.confidence-fill {
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
height: 100%;
transition: width 0.5s ease;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
}
.loading {
display: none;
text-align: center;
padding: 20px;
}
.loading.active {
display: block;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 15px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error {
background: #fee;
border: 2px solid #fcc;
color: #c00;
padding: 15px;
border-radius: 10px;
margin-top: 15px;
display: none;
}
.error.active {
display: block;
}
@media (max-width: 768px) {
.main-content {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>🔢 ruvector-scipix</h1>
<p class="subtitle">Advanced Math OCR in Your Browser</p>
</header>
<div class="main-content">
<div class="upload-section">
<div class="upload-area" id="uploadArea">
<div class="upload-icon">📸</div>
<h3>Drop an image here or click to upload</h3>
<p>Supports PNG, JPG, JPEG, WebP</p>
<input type="file" id="fileInput" class="file-input" accept="image/*">
</div>
<button class="btn" id="processBtn" disabled>
🚀 Process Image
</button>
<div class="preview-container">
<canvas id="preview"></canvas>
</div>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>Processing image...</p>
</div>
<div class="error" id="error"></div>
</div>
<div class="results-section">
<div class="result-box">
<h3>📝 Plain Text</h3>
<div class="result-content" id="textResult">
Results will appear here...
</div>
</div>
<div class="result-box">
<h3>🔢 LaTeX</h3>
<div class="result-content" id="latexResult">
LaTeX output will appear here...
</div>
</div>
<div class="result-box">
<h3>📊 Confidence</h3>
<div class="confidence-bar">
<div class="confidence-fill" id="confidenceFill" style="width: 0%">
0%
</div>
</div>
</div>
</div>
</div>
</div>
<script type="module">
// Note: This demo requires the WASM build of ruvector-scipix
// Build with: wasm-pack build --target web
let wasmModule = null;
let currentImage = null;
// Initialize WASM module
async function initWasm() {
try {
// In production, this would load the actual WASM module
// import init, { MathpixWasm } from './pkg/ruvector_scipix_wasm.js';
// wasmModule = await init();
console.log('WASM module would be initialized here');
// For demo purposes, we'll simulate the OCR
} catch (error) {
showError('Failed to initialize WASM module: ' + error.message);
}
}
// File upload handling
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const processBtn = document.getElementById('processBtn');
const preview = document.getElementById('preview');
uploadArea.addEventListener('click', () => fileInput.click());
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
const file = e.dataTransfer.files[0];
if (file) handleFile(file);
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) handleFile(file);
});
function handleFile(file) {
if (!file.type.startsWith('image/')) {
showError('Please select an image file');
return;
}
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
drawPreview(img);
currentImage = img;
processBtn.disabled = false;
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
function drawPreview(img) {
const ctx = preview.getContext('2d');
const maxWidth = 500;
const maxHeight = 400;
let width = img.width;
let height = img.height;
if (width > maxWidth) {
height *= maxWidth / width;
width = maxWidth;
}
if (height > maxHeight) {
width *= maxHeight / height;
height = maxHeight;
}
preview.width = width;
preview.height = height;
ctx.drawImage(img, 0, 0, width, height);
}
processBtn.addEventListener('click', async () => {
if (!currentImage) return;
showLoading(true);
hideError();
try {
// In production, this would call the actual WASM OCR
// const result = await wasmModule.recognize(imageData);
// For demo, simulate OCR processing
await simulateOcr();
} catch (error) {
showError('OCR processing failed: ' + error.message);
} finally {
showLoading(false);
}
});
async function simulateOcr() {
// Simulate processing delay
await new Promise(resolve => setTimeout(resolve, 2000));
const mockResults = {
text: 'x² + 2x + 1 = 0',
latex: 'x^{2} + 2x + 1 = 0',
confidence: 0.95
};
displayResults(mockResults);
}
function displayResults(results) {
document.getElementById('textResult').textContent = results.text;
document.getElementById('latexResult').textContent = results.latex;
const confidencePct = (results.confidence * 100).toFixed(1);
const confidenceFill = document.getElementById('confidenceFill');
confidenceFill.style.width = confidencePct + '%';
confidenceFill.textContent = confidencePct + '%';
}
function showLoading(show) {
const loading = document.getElementById('loading');
if (show) {
loading.classList.add('active');
processBtn.disabled = true;
} else {
loading.classList.remove('active');
processBtn.disabled = false;
}
}
function showError(message) {
const error = document.getElementById('error');
error.textContent = message;
error.classList.add('active');
}
function hideError() {
document.getElementById('error').classList.remove('active');
}
// Initialize on page load
initWasm();
</script>
</body>
</html>