Update app.py
Browse files
app.py
CHANGED
@@ -18,14 +18,24 @@ def perform_ocr(file):
|
|
18 |
# Verificar si el archivo es un PDF
|
19 |
if file.name.lower().endswith('.pdf'):
|
20 |
# Convertir PDF a imágenes
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
text = ""
|
23 |
for image in images:
|
24 |
text += pytesseract.image_to_string(image) + "\n\n"
|
25 |
else:
|
26 |
# Procesar como imagen
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
return text
|
31 |
|
|
|
18 |
# Verificar si el archivo es un PDF
|
19 |
if file.name.lower().endswith('.pdf'):
|
20 |
# Convertir PDF a imágenes
|
21 |
+
try:
|
22 |
+
images = convert_from_bytes(file.read() if hasattr(file, 'read') else file)
|
23 |
+
except Exception as e:
|
24 |
+
return f"Error al procesar el PDF: {str(e)}"
|
25 |
+
|
26 |
text = ""
|
27 |
for image in images:
|
28 |
text += pytesseract.image_to_string(image) + "\n\n"
|
29 |
else:
|
30 |
# Procesar como imagen
|
31 |
+
try:
|
32 |
+
if hasattr(file, 'read'):
|
33 |
+
image = Image.open(io.BytesIO(file.read()))
|
34 |
+
else:
|
35 |
+
image = Image.open(file)
|
36 |
+
text = pytesseract.image_to_string(image)
|
37 |
+
except Exception as e:
|
38 |
+
return f"Error al procesar la imagen: {str(e)}"
|
39 |
|
40 |
return text
|
41 |
|