import gradio as gr from paddleocr import PaddleOCR import numpy as np # --------------------------------------------------------- # STABILITY CONFIGURATION # enable_mkldnn=False : STOPS the "primitive" crash # cpu_threads=1 : STOPS memory overloading # --------------------------------------------------------- ocr = PaddleOCR( use_angle_cls=False, lang='en', use_gpu=False, enable_mkldnn=False, cpu_threads=1 ) def run_ocr(image): if image is None: return "Error: No Image" try: # Run OCR result = ocr.ocr(image, cls=True) txts = [line[1][0] for line in result[0]] if result and result[0] else [] return "\n".join(txts) except Exception as e: # If it fails, return the error safely return f"Error: {str(e)}" demo = gr.Interface( fn=run_ocr, inputs=gr.Image(type="numpy"), outputs=gr.Textbox(), api_name="predict" ) if __name__ == "__main__": demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)