onursavas commited on
Commit
4645cb2
·
1 Parent(s): 5f8fa54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -1,8 +1,33 @@
1
  import gradio as gr
 
 
 
2
 
 
 
 
 
3
 
4
- def flip_text(x):
5
- return x[::-1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  demo = gr.Blocks()
@@ -16,5 +41,8 @@ with demo:
16
  input_button = gr.Button()
17
  with gr.Column():
18
  output_image = gr.Image()
 
19
 
 
 
20
  demo.launch()
 
1
  import gradio as gr
2
+ from paddleocr import PaddleOCR,draw_ocr
3
+ import json
4
+ import os
5
 
6
+ ocr_ch = PaddleOCR(use_angle_cls=True, lang='en')
7
+ ocr_ch = PaddleOCR(use_angle_cls=True, lang='ch')
8
+ ocr_ru = PaddleOCR(use_angle_cls=True, lang='ru')
9
+ ocr_ru = PaddleOCR(use_angle_cls=True, lang='ar')
10
 
11
+
12
+ def perform_ocr(img, lang):
13
+ ocr = ""
14
+ if lang == "English":
15
+ ocr = ocr_en
16
+ elif lang == "Chinese (Simplified)":
17
+ ocr = ocr_ch
18
+ elif lang == "Russian":
19
+ ocr = ocr_ru
20
+ elif lang == "Arabic":
21
+ ocr = ocr_ar
22
+
23
+ result = ocr.ocr(img.name, cls=True)
24
+ final_result = ""
25
+ for idx in range(len(result)):
26
+ res = result[idx]
27
+ for line in res:
28
+ final_result += str(line)
29
+
30
+ return [img.name, final_result]
31
 
32
 
33
  demo = gr.Blocks()
 
41
  input_button = gr.Button()
42
  with gr.Column():
43
  output_image = gr.Image()
44
+ output_text = gr.Text()
45
 
46
+ btn.click(fn=perform_ocr, inputs=[input_image, input_checkbox], outputs=[output_image, output_text])
47
+
48
  demo.launch()