Ahsen Khaliq commited on
Commit
6cfa281
1 Parent(s): b61c514

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from paddleocr import PaddleOCR,draw_ocr
2
+ from PIL import Image
3
+ import gradio as gr
4
+
5
+ # Paddleocr supports Chinese, English, French, German, Korean and Japanese.
6
+ # You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
7
+ # to switch the language model in order.
8
+ ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load model into memory
9
+ def inference(img):
10
+ img_path = img.name
11
+ result = ocr.ocr(img_path, cls=True)
12
+ for line in result:
13
+ print(line)
14
+
15
+ # draw result
16
+ image = Image.open(img_path).convert('RGB')
17
+ boxes = [line[0] for line in result]
18
+ txts = [line[1][0] for line in result]
19
+ scores = [line[1][1] for line in result]
20
+ im_show = draw_ocr(image, boxes, txts, scores, font_path='simfang.ttf')
21
+ im_show = Image.fromarray(im_show)
22
+ im_show.save('result.jpg')
23
+ return 'result.jpg'
24
+
25
+ title = "PaddleOCR"
26
+ description = "Gradio demo for PaddleOCR. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
27
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2104.05703'>Adversarial Open Domain Adaption for Sketch-to-Photo Synthesis</a> | <a href='https://github.com/Mukosame/Anime2Sketch'>Github Repo</a></p>"
28
+
29
+ gr.Interface(
30
+ inference,
31
+ [gr.inputs.Image(type="file", label="Input")],
32
+ gr.outputs.Image(type="file", label="Output"),
33
+ title=title,
34
+ description=description,
35
+ article=article
36
+ ).launch(debug=True)