Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -5,6 +5,7 @@ from PyPDF2 import PdfReader
|
|
5 |
import tempfile
|
6 |
import os
|
7 |
import shlex
|
|
|
8 |
|
9 |
# Configuraci贸n de logs
|
10 |
logger = logging.getLogger(__name__)
|
@@ -49,7 +50,7 @@ def flujo_principal(pdf_file, idioma="spa"):
|
|
49 |
raise gr.Error("No se subi贸 ning煤n archivo.")
|
50 |
|
51 |
# Utilizar la ruta proporcionada por el archivo subido
|
52 |
-
input_pdf = pdf_file
|
53 |
|
54 |
# Crear un archivo temporal para la salida del OCR
|
55 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_output:
|
@@ -61,7 +62,7 @@ def flujo_principal(pdf_file, idioma="spa"):
|
|
61 |
# Procesar con OCR
|
62 |
crear_pdf_con_texto_incrustado(input_pdf, output_pdf, idioma)
|
63 |
texto_ocr = leer_pdf(output_pdf)
|
64 |
-
return
|
65 |
except gr.Error as e:
|
66 |
logger.error("Error durante el procesamiento del PDF.")
|
67 |
raise e
|
@@ -70,13 +71,13 @@ def flujo_principal(pdf_file, idioma="spa"):
|
|
70 |
if os.path.exists(output_pdf):
|
71 |
os.remove(output_pdf)
|
72 |
|
73 |
-
# Interfaz Gradio
|
74 |
with gr.Blocks() as interfaz:
|
75 |
gr.Markdown("## Procesador OCR para PDFs en Hugging Face")
|
76 |
|
77 |
# Carga de archivo y selecci贸n de idioma
|
78 |
with gr.Row():
|
79 |
-
archivo_pdf =
|
80 |
idioma_ocr = gr.Dropdown(["spa", "eng", "fra", "deu"], label="Idioma OCR", value="spa")
|
81 |
boton_procesar = gr.Button("Procesar OCR")
|
82 |
|
@@ -86,8 +87,8 @@ with gr.Blocks() as interfaz:
|
|
86 |
texto_ocr = gr.Textbox(label="Texto con OCR", lines=10, interactive=False)
|
87 |
|
88 |
with gr.Row():
|
89 |
-
pdf_original_vista =
|
90 |
-
pdf_ocr_vista =
|
91 |
|
92 |
# Conectar la l贸gica con la interfaz
|
93 |
boton_procesar.click(
|
|
|
5 |
import tempfile
|
6 |
import os
|
7 |
import shlex
|
8 |
+
from gradio_pdf import PDF # Importamos el componente PDF espec铆fico de gradio_pdf
|
9 |
|
10 |
# Configuraci贸n de logs
|
11 |
logger = logging.getLogger(__name__)
|
|
|
50 |
raise gr.Error("No se subi贸 ning煤n archivo.")
|
51 |
|
52 |
# Utilizar la ruta proporcionada por el archivo subido
|
53 |
+
input_pdf = pdf_file
|
54 |
|
55 |
# Crear un archivo temporal para la salida del OCR
|
56 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_output:
|
|
|
62 |
# Procesar con OCR
|
63 |
crear_pdf_con_texto_incrustado(input_pdf, output_pdf, idioma)
|
64 |
texto_ocr = leer_pdf(output_pdf)
|
65 |
+
return pdf_file, texto_original, output_pdf, texto_ocr
|
66 |
except gr.Error as e:
|
67 |
logger.error("Error durante el procesamiento del PDF.")
|
68 |
raise e
|
|
|
71 |
if os.path.exists(output_pdf):
|
72 |
os.remove(output_pdf)
|
73 |
|
74 |
+
# Interfaz Gradio usando el componente PDF
|
75 |
with gr.Blocks() as interfaz:
|
76 |
gr.Markdown("## Procesador OCR para PDFs en Hugging Face")
|
77 |
|
78 |
# Carga de archivo y selecci贸n de idioma
|
79 |
with gr.Row():
|
80 |
+
archivo_pdf = PDF(label="Sube tu archivo PDF") # Usamos PDF en lugar de gr.File
|
81 |
idioma_ocr = gr.Dropdown(["spa", "eng", "fra", "deu"], label="Idioma OCR", value="spa")
|
82 |
boton_procesar = gr.Button("Procesar OCR")
|
83 |
|
|
|
87 |
texto_ocr = gr.Textbox(label="Texto con OCR", lines=10, interactive=False)
|
88 |
|
89 |
with gr.Row():
|
90 |
+
pdf_original_vista = PDF(label="Vista del PDF Original", interactive=False)
|
91 |
+
pdf_ocr_vista = PDF(label="Vista del PDF con OCR", interactive=False)
|
92 |
|
93 |
# Conectar la l贸gica con la interfaz
|
94 |
boton_procesar.click(
|