Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from paddleocr import PaddleOCR
|
| 3 |
-
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
# ---------------------------------------------------------
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
-
#
|
| 10 |
-
# 3. use_angle_cls=False -> 30% FASTER speed (Skins are always upright)
|
| 11 |
# ---------------------------------------------------------
|
| 12 |
ocr = PaddleOCR(
|
| 13 |
-
use_angle_cls=False,
|
| 14 |
lang='en',
|
| 15 |
use_gpu=False,
|
| 16 |
-
enable_mkldnn=False,
|
| 17 |
cpu_threads=1
|
| 18 |
)
|
| 19 |
|
| 20 |
def run_ocr(image):
|
| 21 |
-
if image is None: return "Error: No
|
| 22 |
try:
|
| 23 |
-
#
|
| 24 |
result = ocr.ocr(image, cls=True)
|
| 25 |
txts = [line[1][0] for line in result[0]] if result and result[0] else []
|
| 26 |
return "\n".join(txts)
|
| 27 |
except Exception as e:
|
|
|
|
| 28 |
return f"Error: {str(e)}"
|
| 29 |
|
| 30 |
-
# Define the interface with explicit API name
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=run_ocr,
|
| 33 |
inputs=gr.Image(type="numpy"),
|
|
@@ -35,6 +33,5 @@ demo = gr.Interface(
|
|
| 35 |
api_name="predict"
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# Queue max_size=20 prevents the server from freezing if you spam it
|
| 39 |
if __name__ == "__main__":
|
| 40 |
demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from paddleocr import PaddleOCR
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
# ---------------------------------------------------------
|
| 6 |
+
# STABILITY CONFIGURATION
|
| 7 |
+
# enable_mkldnn=False : STOPS the "primitive" crash
|
| 8 |
+
# cpu_threads=1 : STOPS memory overloading
|
|
|
|
| 9 |
# ---------------------------------------------------------
|
| 10 |
ocr = PaddleOCR(
|
| 11 |
+
use_angle_cls=False,
|
| 12 |
lang='en',
|
| 13 |
use_gpu=False,
|
| 14 |
+
enable_mkldnn=False,
|
| 15 |
cpu_threads=1
|
| 16 |
)
|
| 17 |
|
| 18 |
def run_ocr(image):
|
| 19 |
+
if image is None: return "Error: No Image"
|
| 20 |
try:
|
| 21 |
+
# Run OCR
|
| 22 |
result = ocr.ocr(image, cls=True)
|
| 23 |
txts = [line[1][0] for line in result[0]] if result and result[0] else []
|
| 24 |
return "\n".join(txts)
|
| 25 |
except Exception as e:
|
| 26 |
+
# If it fails, return the error safely
|
| 27 |
return f"Error: {str(e)}"
|
| 28 |
|
|
|
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=run_ocr,
|
| 31 |
inputs=gr.Image(type="numpy"),
|
|
|
|
| 33 |
api_name="predict"
|
| 34 |
)
|
| 35 |
|
|
|
|
| 36 |
if __name__ == "__main__":
|
| 37 |
demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)
|