Spaces:
Runtime error
Runtime error
tomaseo2022
commited on
Commit
•
c5853b7
1
Parent(s):
b403db6
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
os.system("pip install PyMuPDF")
|
3 |
import gradio as gr
|
4 |
import fitz # PyMuPDF
|
|
|
5 |
|
6 |
def pdf_to_xml(pdf_file):
|
7 |
try:
|
@@ -19,11 +20,14 @@ def pdf_to_xml(pdf_file):
|
|
19 |
if len(pdf_text) > max_chars:
|
20 |
pdf_text = pdf_text[:max_chars]
|
21 |
|
22 |
-
#
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
return
|
27 |
|
28 |
except Exception as e:
|
29 |
return f"Error al procesar el archivo: {str(e)}"
|
|
|
2 |
os.system("pip install PyMuPDF")
|
3 |
import gradio as gr
|
4 |
import fitz # PyMuPDF
|
5 |
+
import tempfile
|
6 |
|
7 |
def pdf_to_xml(pdf_file):
|
8 |
try:
|
|
|
20 |
if len(pdf_text) > max_chars:
|
21 |
pdf_text = pdf_text[:max_chars]
|
22 |
|
23 |
+
# Crear un archivo temporal para almacenar el texto
|
24 |
+
temp_dir = tempfile.mkdtemp()
|
25 |
+
temp_file_path = os.path.join(temp_dir, "converted_text.txt")
|
26 |
+
with open(temp_file_path, "w") as temp_file:
|
27 |
+
temp_file.write(pdf_text)
|
28 |
|
29 |
+
# Devolver la ruta del archivo temporal
|
30 |
+
return temp_file_path
|
31 |
|
32 |
except Exception as e:
|
33 |
return f"Error al procesar el archivo: {str(e)}"
|