File size: 922 Bytes
bf6343f 64fe5a9 b16b8c7 01dfe28 bf6343f 66baacc 01dfe28 66baacc 01dfe28 64fe5a9 bf6343f 66baacc 64fe5a9 66baacc bf6343f 990b2f4 64fe5a9 bf6343f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
from PIL import Image
import pytesseract
import fitz # PyMuPDF
def ocr_pdf(file):
# Abre el PDF
doc = fitz.open(file.name)
text = ""
for page_number in range(len(doc)):
# Extrae la página como imagen
page = doc.load_page(page_number)
pix = page.get_pixmap()
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
# Extrae texto de la imagen
text += pytesseract.image_to_string(img) + "\n"
return text
# Crea la interfaz de Gradio
iface = gr.Interface(
fn=ocr_pdf, # Función que procesa el PDF
inputs=gr.File(label="Sube tu archivo PDF"), # Tipo de entrada: archivo
outputs=gr.Textbox(label="Texto extraído"), # Tipo de salida: texto
title="OCR con Python Tesseract para PDF",
description="Sube un archivo PDF para extraer el texto usando Tesseract OCR."
)
# Ejecuta la interfaz
iface.launch() |