Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from paddleocr import PaddleOCR | |
| from PIL import Image | |
| import numpy as np | |
| # Inicializar PaddleOCR com suporte a português | |
| ocr = PaddleOCR(use_angle_cls=True, lang='pt', show_log=False) | |
| def ocr_paddle(image): | |
| if image is None: | |
| return "Por favor, envie uma imagem com texto." | |
| # Converter PIL para array numpy (formato esperado pelo PaddleOCR) | |
| img = np.array(image) | |
| # Realizar OCR | |
| result = ocr.ocr(img, cls=True) | |
| # Extrair textos detectados | |
| textos = [] | |
| for linha in result: | |
| for caixa in linha: | |
| texto = caixa[1][0] | |
| textos.append(texto) | |
| if not textos: | |
| return "Nenhum texto foi detectado na imagem." | |
| return "\n".join(textos) | |
| # Interface Gradio | |
| 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 estilo Google Lens 🧠", | |
| description="Extrai texto de imagens, como rótulos, embalagens, documentos e placas. Powered by PaddleOCR." | |
| ) | |
| if __name__ == "__main__": | |
| interface.launch() | |