|
import gradio as gr |
|
from PIL import Image |
|
import pytesseract |
|
import fitz |
|
|
|
def ocr_pdf(file): |
|
|
|
doc = fitz.open(file.name) |
|
text = "" |
|
for page_number in range(len(doc)): |
|
|
|
page = doc.load_page(page_number) |
|
pix = page.get_pixmap() |
|
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples) |
|
|
|
text += pytesseract.image_to_string(img) + "\n" |
|
return text |
|
|
|
|
|
iface = gr.Interface( |
|
fn=ocr_pdf, |
|
inputs=gr.File(label="Sube tu archivo PDF"), |
|
outputs=gr.Textbox(label="Texto extraído"), |
|
title="OCR con Python Tesseract para PDF", |
|
description="Sube un archivo PDF para extraer el texto usando Tesseract OCR." |
|
) |
|
|
|
|
|
iface.launch() |