OCR de imagenes con Mistral: ImageProcessor (png/jpg/webp/gif/bmp/tiff), modelo mistral-ocr-latest y recuperacion de fuentes unknown

This commit is contained in:
urieljareth
2026-09-13 22:39:39 -06:00
parent 239a7510c6
commit 15cf00cc42
12 changed files with 79 additions and 14 deletions
@@ -51,7 +51,7 @@ export default function WeekPage({ params }: { params: { subjectId: string; week
setUploading(true); setError("");
try {
const ranges = pageMode === "ranges" ? pageRanges : undefined;
for (const file of files) await api.upload(subjectId, weekNumber, file, pdfMethod === "mistral_ocr", ranges);
for (const file of files) await api.upload(subjectId, weekNumber, file, isImageFile(file) || pdfMethod === "mistral_ocr", ranges);
await load();
} catch (err) {
setError(err instanceof Error ? err.message : "No se pudo subir archivo");
@@ -65,6 +65,10 @@ export default function WeekPage({ params }: { params: { subjectId: string; week
return file.type === "application/pdf" || file.name.toLowerCase().endsWith(".pdf");
}
function isImageFile(file: File) {
return file.type.startsWith("image/") || /\.(png|jpe?g|webp|gif|bmp|tiff?)$/i.test(file.name);
}
async function prepareFiles(files: File[]) {
if (!files.length) return;
setError("");
@@ -136,8 +140,10 @@ export default function WeekPage({ params }: { params: { subjectId: string; week
async function reprocessSource(source: Source) {
setReprocessingId(source.id); setError("");
try {
const ranges = source.source_type === "pdf" && pageMode === "ranges" ? pageRanges : undefined;
await api.reprocessSource(source.id, source.source_type === "pdf" && pdfMethod === "mistral_ocr", ranges);
const isPdf = source.source_type === "pdf";
const ranges = isPdf && pageMode === "ranges" ? pageRanges : undefined;
const useOcr = isPdf ? pdfMethod === "mistral_ocr" : source.source_type === "image";
await api.reprocessSource(source.id, useOcr, ranges);
await load();
} catch (err) {
setError(err instanceof Error ? err.message : "No se pudo reprocesar la fuente");
@@ -187,11 +193,11 @@ export default function WeekPage({ params }: { params: { subjectId: string; week
<div className="flex flex-wrap items-center justify-between gap-4">
<div>
<h2 className="text-xl font-semibold">Subir archivos</h2>
<p className="mt-1 text-sm text-slate-400">PDF, DOCX, TXT, Markdown, audio y video.</p>
<p className="mt-1 text-sm text-slate-400">PDF, DOCX, TXT, Markdown, imagenes, audio y video.</p>
</div>
<label className="cursor-pointer rounded-xl bg-blue-600 px-4 py-2 font-medium hover:bg-blue-500">
{uploading ? "Subiendo..." : "Seleccionar archivos"}
<input className="hidden" type="file" multiple onChange={uploadFiles} disabled={uploading} />
<input className="hidden" type="file" multiple onChange={uploadFiles} disabled={uploading} accept=".pdf,.docx,.txt,.md,.png,.jpg,.jpeg,.webp,.gif,.bmp,.tif,.tiff,.mp3,.wav,.m4a,.ogg,.flac,.webm,.mp4,.mov,.mkv,.avi" />
</label>
</div>
<div
@@ -204,7 +210,7 @@ export default function WeekPage({ params }: { params: { subjectId: string; week
<div className="mx-auto grid h-14 w-14 place-items-center rounded-2xl bg-blue-500/15 text-2xl">↑</div>
<p className="mt-4 font-medium">Arrastra archivos aqui</p>
<p className="mt-2 text-sm text-slate-400">Puedes soltar varios archivos a la vez. Se procesaran en esta semana.</p>
<p className="mt-3 text-xs text-slate-500">Soporta PDF, DOCX, TXT, Markdown, audio y video.</p>
<p className="mt-3 text-xs text-slate-500">Soporta PDF, DOCX, TXT, Markdown, imagenes (OCR automatico), audio y video.</p>
{uploading && <p className="mt-4 text-sm text-blue-300">Subiendo archivos...</p>}
</div>
{pendingFiles.length > 0 && (