eberhenriquez94 commited on
Commit
bea5cb9
verified
1 Parent(s): d08fa6a
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -46,9 +46,8 @@ def flujo_principal(pdf_file, idioma="spa"):
46
  if not pdf_file:
47
  raise gr.Error("No se subi贸 ning煤n archivo.")
48
 
49
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_input:
50
- temp_input.write(pdf_file.read())
51
- input_pdf = temp_input.name
52
 
53
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_output:
54
  output_pdf = temp_output.name
@@ -60,16 +59,14 @@ def flujo_principal(pdf_file, idioma="spa"):
60
  texto_ocr = leer_pdf(output_pdf)
61
  return gr.File(input_pdf, label="PDF Original"), texto_original, gr.File(output_pdf, label="PDF con OCR"), texto_ocr
62
  except gr.Error as e:
63
- # Limpieza en caso de error
64
- os.remove(input_pdf)
65
- if os.path.exists(output_pdf):
 
 
 
 
66
  os.remove(output_pdf)
67
- raise e # Re-lanzar la excepci贸n para que Gradio la maneje
68
- finally: # Limpieza, incluso si hay excepciones
69
- if os.path.exists(input_pdf): os.remove(input_pdf)
70
- if os.path.exists(output_pdf): os.remove(output_pdf)
71
-
72
-
73
 
74
  # Interfaz Gradio
75
  with gr.Blocks() as interfaz:
 
46
  if not pdf_file:
47
  raise gr.Error("No se subi贸 ning煤n archivo.")
48
 
49
+ # Usa la ruta del archivo directamente
50
+ input_pdf = pdf_file.name
 
51
 
52
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_output:
53
  output_pdf = temp_output.name
 
59
  texto_ocr = leer_pdf(output_pdf)
60
  return gr.File(input_pdf, label="PDF Original"), texto_original, gr.File(output_pdf, label="PDF con OCR"), texto_ocr
61
  except gr.Error as e:
62
+ # Limpieza en caso de error
63
+ if os.path.exists(output_pdf):
64
+ os.remove(output_pdf)
65
+ raise e # Re-lanzar la excepci贸n para que Gradio la maneje
66
+ finally:
67
+ # Limpieza, incluso si hay excepciones
68
+ if os.path.exists(output_pdf):
69
  os.remove(output_pdf)
 
 
 
 
 
 
70
 
71
  # Interfaz Gradio
72
  with gr.Blocks() as interfaz: