|
import gradio as gr |
|
from PIL import Image |
|
import pytesseract |
|
from pdf2image import convert_from_path |
|
import os |
|
|
|
|
|
|
|
|
|
|
|
def ocr_pdf(file): |
|
|
|
images = convert_from_path(file.name) |
|
text = "" |
|
for image in images: |
|
|
|
text += pytesseract.image_to_string(image) + "\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() |