Download app.py from ivoryxs/teste_2: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/ivoryxs/teste_2/resolve/main/app.py
- Command line
-
hf download hf://spaces/ivoryxs/teste_2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ivoryxs/teste_2/resolve/main/app.py
1.01 kB
| 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() | |