Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from vietocr.tool.predictor import Predictor
|
4 |
+
from vietocr.tool.config import Cfg
|
5 |
+
|
6 |
+
|
7 |
+
config = Cfg.load_config_from_name('vgg_transformer')
|
8 |
+
config['weights'] = 'ocr.pth'
|
9 |
+
config['device'] = 'cuda:0'
|
10 |
+
config['cnn']['pretrained']=False
|
11 |
+
config['predictor']['beamsearch']=False
|
12 |
+
|
13 |
+
detector = Predictor(config)
|
14 |
+
|
15 |
+
|
16 |
+
def run(source):
|
17 |
+
global detector
|
18 |
+
img = Image.open(source)
|
19 |
+
img = img.convert('L')
|
20 |
+
result = detector.predict(img)
|
21 |
+
return result
|
22 |
+
|
23 |
+
|
24 |
+
gr.Interface(
|
25 |
+
run,
|
26 |
+
inputs=gr.Image(label="Upload image", type="filepath"),
|
27 |
+
outputs="label",
|
28 |
+
title="Transformer Ocr",
|
29 |
+
).launch()
|