pdf-csv-agent / static /index.html
Stephan86's picture
Claude Opus 4.8
merge: fusion nettoyeur CSV (HF) + extracteur PDF→CSV EBP en une codebase
be49328
Raw History Blame Contribute Delete
13 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nettoyeur CSV</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0f1117;
--surface: #1a1d27;
--border: #2a2d3e;
--accent: #6366f1;
--accent-hover: #4f46e5;
--text: #e2e8f0;
--muted: #64748b;
--success: #10b981;
--error: #ef4444;
}
body {
background: var(--bg);
color: var(--text);
font-family: system-ui, -apple-system, sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem 1rem 4rem;
}
header { text-align: center; margin-bottom: 2.5rem; }
header h1 {
font-size: 2.2rem;
font-weight: 700;
background: linear-gradient(135deg, #6366f1, #a78bfa);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: .5rem;
}
header p { color: var(--muted); font-size: 1rem; }
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 16px;
padding: 2rem;
width: 100%;
max-width: 680px;
}
.drop-zone {
border: 2px dashed var(--border);
border-radius: 12px;
padding: 2.5rem 1rem;
text-align: center;
cursor: pointer;
transition: border-color .2s, background .2s;
margin-bottom: 1.5rem;
position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
border-color: var(--accent);
background: rgba(99,102,241,.06);
}
.drop-zone input[type="file"] {
position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.drop-zone .icon { font-size: 2.5rem; margin-bottom: .75rem; }
.drop-zone .label { font-size: .95rem; color: var(--muted); }
.drop-zone .label strong { color: var(--accent); }
.drop-zone .file-name {
margin-top: .75rem; font-size: .85rem; color: var(--success); font-weight: 600;
}
.options { margin-bottom: 1.5rem; }
.options h3 { font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.opt {
display: flex; align-items: flex-start; gap: .65rem;
padding: .7rem .85rem; border: 1px solid var(--border); border-radius: 10px;
margin-bottom: .6rem; cursor: pointer; transition: border-color .2s, background .2s;
}
.opt:hover { border-color: var(--accent); background: rgba(99,102,241,.04); }
.opt input { margin-top: .2rem; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); cursor: pointer; }
.opt .opt-text { display: flex; flex-direction: column; gap: .15rem; }
.opt .opt-title { font-size: .92rem; color: var(--text); font-weight: 500; }
.opt .opt-desc { font-size: .78rem; color: var(--muted); }
button[type="submit"] {
width: 100%; padding: .85rem; background: var(--accent); color: #fff;
border: none; border-radius: 10px; font-size: 1rem; font-weight: 600;
cursor: pointer; transition: background .2s, opacity .2s;
}
button[type="submit"]:hover:not(:disabled) { background: var(--accent-hover); }
button[type="submit"]:disabled { opacity: .5; cursor: not-allowed; }
.progress-wrap { margin-top: 1.25rem; display: none; }
.progress-wrap.visible { display: block; }
.progress-bar-bg { background: var(--border); border-radius: 999px; height: 6px; overflow: hidden; margin-bottom: .5rem; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 999px; width: 0%; transition: width .4s ease; }
.progress-label { font-size: .83rem; color: var(--muted); text-align: center; }
.result { margin-top: 1.25rem; border-radius: 10px; padding: 1rem 1.25rem; display: none; }
.result.success { display: block; background: rgba(16,185,129,.08); border: 1px solid rgba(16,185,129,.3); }
.result.error { display: block; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: var(--error); font-size: .88rem; white-space: pre-wrap; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.result-head .summary { font-size: .9rem; color: var(--success); }
.result-head .summary strong { font-size: 1.05rem; }
.download-btn {
padding: .55rem 1.1rem; background: var(--success); color: #fff; border: none;
border-radius: 8px; font-size: .85rem; font-weight: 600; cursor: pointer;
text-decoration: none; transition: opacity .2s; white-space: nowrap;
}
.download-btn:hover { opacity: .85; }
.report-meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .78rem; color: var(--muted); margin-bottom: .8rem; }
.report-meta span strong { color: var(--text); }
.actions-list { list-style: none; font-size: .85rem; color: var(--text); }
.actions-list li { padding: .25rem 0 .25rem 1.2rem; position: relative; }
.actions-list li::before { content: "✓"; position: absolute; left: 0; color: var(--success); }
footer { margin-top: 2rem; font-size: .78rem; color: var(--muted); text-align: center; }
footer a { color: var(--accent); text-decoration: none; }
</style>
</head>
<body>
<header>
<h1>Nettoyeur CSV</h1>
<p>Charge un CSV, choisis le nettoyage, récupère un fichier propre.</p>
<p><a href="/extracteur" style="color:#7aa2f7;">→ Extracteur catalogue PDF → CSV EBP (sous-familles + aperçu éditable)</a></p>
</header>
<div class="card">
<form id="form">
<div class="drop-zone" id="dropZone">
<input type="file" name="csv_file" id="csvInput" accept=".csv,.tsv,.txt" required />
<div class="icon">🧹</div>
<div class="label">Glisse ton CSV ici ou <strong>clique pour choisir</strong></div>
<div class="file-name" id="fileName"></div>
</div>
<div class="options">
<h3>Opérations de nettoyage</h3>
<label class="opt">
<input type="checkbox" name="drop_empty" checked />
<span class="opt-text">
<span class="opt-title">Lignes & colonnes vides</span>
<span class="opt-desc">Supprime les lignes et colonnes entièrement vides.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="drop_duplicates" checked />
<span class="opt-text">
<span class="opt-title">Doublons</span>
<span class="opt-desc">Supprime les lignes identiques en double.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="trim_whitespace" checked />
<span class="opt-text">
<span class="opt-title">Espaces superflus</span>
<span class="opt-desc">Nettoie les espaces en début/fin et les doubles espaces.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="normalize_headers" checked />
<span class="opt-text">
<span class="opt-title">En-têtes propres</span>
<span class="opt-desc">Nettoie et dé-duplique les noms de colonnes.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="remove_symbols" />
<span class="opt-text">
<span class="opt-title">Retirer les symboles</span>
<span class="opt-desc">Supprime €, %, #, *, ®… en gardant lettres et chiffres (12,50 € → 12,50, Réf#12 → Réf12).</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="keep_digits_only" />
<span class="opt-text">
<span class="opt-title">Garder uniquement les chiffres</span>
<span class="opt-desc">Retire lettres et symboles des cellules contenant un nombre (12,50€ → 12,50, A123 → 123). N'active que si une colonne de montants contient des lettres.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="decimal_comma" />
<span class="opt-text">
<span class="opt-title">Virgule décimale (FR)</span>
<span class="opt-desc">Convertit 1234.56 → 1234,56 et retire les séparateurs de milliers.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="ebp_format" />
<span class="opt-text">
<span class="opt-title">Format EBP</span>
<span class="opt-desc">Sortie séparateur « ; », encodage UTF-8 BOM, fins de ligne Windows.</span>
</span>
</label>
</div>
<button type="submit" id="submitBtn">Nettoyer le CSV</button>
<div class="progress-wrap" id="progressWrap">
<div class="progress-bar-bg"><div class="progress-bar" id="progressBar"></div></div>
<div class="progress-label" id="progressLabel">Nettoyage en cours…</div>
</div>
<div class="result" id="result"></div>
</form>
</div>
<footer>
<a href="https://github.com/boutique-oss/convertionpdfcsv" target="_blank">Code source</a>
&nbsp;·&nbsp; Nettoyage 100 % local, sans IA
</footer>
<script>
const dropZone = document.getElementById('dropZone');
const csvInput = document.getElementById('csvInput');
const fileName = document.getElementById('fileName');
csvInput.addEventListener('change', () => {
if (csvInput.files[0]) fileName.textContent = csvInput.files[0].name;
});
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('drag-over'); });
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over'));
dropZone.addEventListener('drop', e => {
e.preventDefault();
dropZone.classList.remove('drag-over');
const f = e.dataTransfer.files[0];
if (f) {
const dt = new DataTransfer();
dt.items.add(f);
csvInput.files = dt.files;
fileName.textContent = f.name;
}
});
const form = document.getElementById('form');
const submitBtn = document.getElementById('submitBtn');
const progressWrap = document.getElementById('progressWrap');
const progressBar = document.getElementById('progressBar');
const progressLbl = document.getElementById('progressLabel');
const result = document.getElementById('result');
form.addEventListener('submit', async e => {
e.preventDefault();
if (!csvInput.files[0]) {
result.className = 'result error';
result.textContent = 'Choisis d\'abord un fichier CSV.';
return;
}
result.className = 'result';
result.innerHTML = '';
progressWrap.classList.add('visible');
progressBar.style.width = '15%';
progressLbl.textContent = 'Envoi du fichier…';
submitBtn.disabled = true;
try {
const base = window.location.origin;
const fd = new FormData();
fd.append('csv_file', csvInput.files[0]);
['drop_empty','drop_duplicates','trim_whitespace','normalize_headers','remove_symbols','keep_digits_only','decimal_comma','ebp_format']
.forEach(name => {
const el = form.querySelector(`[name="${name}"]`);
fd.append(name, el.checked ? 'true' : 'false');
});
progressBar.style.width = '50%';
progressLbl.textContent = 'Nettoyage en cours…';
const resp = await fetch(`${base}/clean`, { method: 'POST', body: fd });
if (!resp.ok) {
let detail = 'Erreur serveur';
try { detail = (await resp.json()).detail; } catch (_) {}
throw new Error(`${detail}`);
}
const { download_id, report } = await resp.json();
progressBar.style.width = '100%';
progressWrap.classList.remove('visible');
const dlUrl = `${base}/download/${download_id}`;
const sep = report.separateur_sortie === '\t' ? 'tab' : report.separateur_sortie;
const actions = (report.actions || []).map(a => `<li>${a}</li>`).join('');
result.className = 'result success';
result.innerHTML = `
<div class="result-head">
<div class="summary"><strong>${report.lignes_finales}</strong> lignes · ${report.colonnes_finales} colonnes</div>
<a class="download-btn" href="${dlUrl}">Télécharger</a>
</div>
<div class="report-meta">
<span>Entrée&nbsp;: <strong>${report.lignes_initiales}</strong> lignes, sép. «&nbsp;${report.separateur_detecte}&nbsp;», ${report.encodage_detecte}</span>
<span>Sortie&nbsp;: sép. «&nbsp;${sep}&nbsp;», ${report.encodage_sortie}</span>
</div>
<ul class="actions-list">${actions}</ul>
`;
} catch (err) {
progressWrap.classList.remove('visible');
result.className = 'result error';
result.textContent = err.message;
} finally {
submitBtn.disabled = false;
}
});
</script>
</body>
</html>