kkpathak91 commited on
Commit
0ebe145
1 Parent(s): 594a060

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -41
app.py CHANGED
@@ -1,45 +1,5 @@
1
- import os
2
- os.system('pip install paddlepaddle')
3
- os.system('pip install paddleocr')
4
- from paddleocr import PaddleOCR, draw_ocr
5
- from PIL import Image
6
- import gradio as gr
7
- import torch
8
 
9
- torch.hub.download_url_to_file('https://i.imgur.com/aqMBT0i.jpg', 'example.jpg')
10
-
11
- def inference(img, lang):
12
- ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
13
- img_path = img.name
14
- result = ocr.ocr(img_path, cls=True)
15
- image = Image.open(img_path).convert('RGB')
16
- boxes = [line[0] for line in result]
17
- txts = [line[1][0] for line in result]
18
- # scores = [line[1][1] for line in result]
19
- im_show = draw_ocr(image, boxes, txts,
20
- font_path='simfang.ttf')
21
- im_show = Image.fromarray(im_show)
22
- im_show.save('result.jpg')
23
- return 'result.jpg'
24
-
25
- title = 'A Framework for Data-Driven Document Evaluation and scoring - Image to Text Extraction '
26
- description = 'Demo for Optical character recognition(OCR)'
27
- article = ""
28
- examples = [['example.jpg','en']]
29
- css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
30
- gr.Interface(
31
- inference,
32
- [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='en', label='language')],
33
- gr.outputs.Image(type='file', label='Output'),
34
- title=title,
35
- description=description,
36
- article=article,
37
- examples=examples,
38
- css=css,
39
- enable_queue=True
40
- ).launch(debug=True)
41
-
42
-
43
  ##########################################################################################################
44
 
45
  import os
 
 
 
 
 
 
 
1
 
2
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ##########################################################################################################
4
 
5
  import os