|
|
import gradio as gr |
|
|
from paddleocr import PaddleOCR |
|
|
from PIL import Image |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
ocr = PaddleOCR(lang='pt') |
|
|
|
|
|
def ocr_paddle(image): |
|
|
if image is None: |
|
|
return "Por favor, envie uma imagem." |
|
|
|
|
|
|
|
|
img = np.array(image.convert("RGB")) |
|
|
|
|
|
|
|
|
result = ocr.ocr(img) |
|
|
|
|
|
|
|
|
textos = [] |
|
|
for linha in result: |
|
|
for caixa in linha: |
|
|
texto = caixa[1][0] |
|
|
textos.append(texto) |
|
|
|
|
|
if not textos: |
|
|
return "Nenhum texto detectado." |
|
|
|
|
|
return "\n".join(textos) |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=ocr_paddle, |
|
|
inputs=gr.Image(type="pil", label="Envie uma imagem com texto"), |
|
|
outputs=gr.Textbox(label="Texto extraído"), |
|
|
title="OCR com PaddleOCR", |
|
|
description="Extrai texto visível de imagens como rótulos, embalagens e documentos." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
interface.launch() |
|
|
|