Spaces:
Runtime error
Runtime error
File size: 1,031 Bytes
5b2c368 41311bb 6b1b55d 5b2c368 6b1b55d 5b2c368 6b1b55d 5b2c368 6b1b55d 41311bb 6b1b55d |
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 30 31 32 33 |
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()
|