Spaces:
Runtime error
Runtime error
import gradio as gr | |
from doctr.models import ocr_predictor | |
from doctr.io import DocumentFile | |
# Cargar el modelo OCR de DocTR | |
ocr_model = ocr_predictor(pretrained=True) | |
# Funci贸n para procesar un PDF y extraer texto | |
def extract_text_from_pdf(pdf_file): | |
# Leer el PDF con DocTR | |
doc = DocumentFile.from_pdf(pdf_file) | |
# Ejecutar el OCR | |
result = ocr_model(doc) | |
# Extraer el texto | |
text = "\n".join([block[1] for page in result.pages for block in page.blocks]) | |
return text | |
# Crear la interfaz Gradio | |
with gr.Blocks() as demo: | |
gr.Markdown("# DocTR OCR para PDFs con Gradio") | |
gr.Markdown("Sube un archivo PDF para extraer el texto.") | |
with gr.Row(): | |
pdf_input = gr.File(label="Sube tu PDF", type="file") | |
text_output = gr.Textbox(label="Texto Extra铆do", lines=10) | |
extract_button = gr.Button("Extraer Texto") | |
extract_button.click(extract_text_from_pdf, inputs=pdf_input, outputs=text_output) | |
# Ejecutar la aplicaci贸n | |
if __name__ == "__main__": | |
demo.launch() | |