Spaces:
Build error
Build error
app.py
CHANGED
@@ -49,27 +49,10 @@ def flujo_principal(pdf_file, idioma="spa"):
|
|
49 |
# Guardar el archivo subido en el directorio /tmp
|
50 |
temp_dir = tempfile.mkdtemp()
|
51 |
input_pdf_path = os.path.join(temp_dir, pdf_file.name)
|
52 |
-
with open(input_pdf_path, "wb") as f:
|
53 |
-
f.write(pdf_file.read())
|
54 |
-
|
55 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf", dir=temp_dir) as temp_output:
|
56 |
-
output_pdf_path = temp_output.name
|
57 |
-
|
58 |
-
texto_original = leer_pdf(input_pdf_path)
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
return gr.File(input_pdf_path, label="PDF Original"), texto_original, gr.File(output_pdf_path, label="PDF con OCR"), texto_ocr
|
64 |
-
except gr.Error as e:
|
65 |
-
raise e
|
66 |
-
finally:
|
67 |
-
# Limpiar archivos temporales
|
68 |
-
if os.path.exists(input_pdf_path):
|
69 |
-
os.remove(input_pdf_path)
|
70 |
-
if os.path.exists(output_pdf_path):
|
71 |
-
os.remove(output_pdf_path)
|
72 |
-
os.rmdir(temp_dir)
|
73 |
|
74 |
# Interfaz Gradio
|
75 |
with gr.Blocks() as interfaz:
|
|
|
49 |
# Guardar el archivo subido en el directorio /tmp
|
50 |
temp_dir = tempfile.mkdtemp()
|
51 |
input_pdf_path = os.path.join(temp_dir, pdf_file.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
# Usar pdf_file.name para acceder al contenido del archivo
|
54 |
+
with open(input_pdf_path, "wb") as f:
|
55 |
+
f.write(open(pdf_file.name, "rb").read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Interfaz Gradio
|
58 |
with gr.Blocks() as interfaz:
|