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
+14
View File
@@ -378,6 +378,18 @@ class KnowledgeManager:
raise ValueError("Fuente no encontrada")
return dict(row)
def refresh_source_type(self, source_id: int) -> str:
"""Recalcula y persiste el tipo de una fuente guardada como ``unknown``.
Permite reprocesar archivos subidos antes de soportar su formato
(por ejemplo, imagenes que quedaron como ``unknown`` y fallaban).
"""
source = self.get_source(source_id)
source_type = self.detect_source_type(Path(source["stored_path"]))
with self._connect() as conn:
conn.execute("update sources set source_type = ? where id = ?", (source_type, source_id))
return source_type
def list_sources(self, subject_id: int, week_number: int) -> list[dict[str, Any]]:
week = self.get_week(subject_id, week_number)
with self._connect() as conn:
@@ -552,6 +564,8 @@ class KnowledgeManager:
return "docx"
if ext == "pdf":
return "pdf"
if ext in {"png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff"}:
return "image"
if ext in {"mp3", "wav", "m4a", "ogg", "flac", "webm"}:
return "audio"
if ext in {"mp4", "mov", "mkv", "avi"}: