File size: 1,011 Bytes
1760e79
1288bb2
1760e79
 
 
1288bb2
 
1760e79
 
 
1288bb2
1760e79
1288bb2
e77b421
1760e79
1288bb2
 
1760e79
1288bb2
1760e79
 
 
1288bb2
 
1760e79
 
e77b421
1760e79
 
 
1288bb2
 
 
 
1760e79
1288bb2
 
1760e79
 
 
1288bb2
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
34
35
36
37
38
39
40
41
42
import gradio as gr
from paddleocr import PaddleOCR
from PIL import Image
import numpy as np

# Inicializa o OCR (versão estável)
ocr = PaddleOCR(lang='pt')  # você pode trocar para 'en', 'ch', etc.

def ocr_paddle(image):
    if image is None:
        return "Por favor, envie uma imagem."

    # Converter imagem para array
    img = np.array(image.convert("RGB"))

    # Rodar OCR
    result = ocr.ocr(img)

    # Extrair textos
    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
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()