Vihang28 commited on
Commit
778d92a
·
1 Parent(s): f1d50ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from paddleocr import PaddleOCR, draw_ocr
2
+ from matplotlib import pyplot as plt
3
+ import cv2
4
+ import os
5
+ import gradio as gr
6
+ from typing import List
7
+
8
+ lst = [state.name for state in us.states.STATES_AND_TERRITORIES]
9
+ sst_lst = []
10
+ for i in lst:
11
+ sst_lst.append(i.upper())
12
+ def ocr_model(filepath: str, languages: List[str]=None):
13
+ pocr_model = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=False)
14
+ # img_path = os.path.join('.', 'static', 'img10.jpg')
15
+ result = pocr_model.ocr(filepath)
16
+ state_txt = ""
17
+ for res in result :
18
+ state_txt += res[1][0] + "\n"
19
+ return state_txt
20
+
21
+ title = "US Vehicle Number Plate"
22
+ description = "Gradio demo for PaddlePaddle. PaddleOCR is an open source text recognition (OCR) Engine."
23
+ article = "<p style='text-align: center'><a href='https://github.com/PaddlePaddle/PaddleOCR' target='_blank'>Github Repo</a></p>"
24
+
25
+ with gr.Blocks(title=title) as demo:
26
+ gr.Markdown(f'<h1 style="text-align: center; margin-bottom: 1rem;">{title}</h1>')
27
+ gr.Markdown(description)
28
+ with gr.Row():
29
+ with gr.Column():
30
+ image = gr.Image(type="filepath", label="Input")
31
+ with gr.Row():
32
+ btn_clear = gr.ClearButton([image])
33
+ btn_submit = gr.Button(value="Submit", variant="primary")
34
+ with gr.Column():
35
+ text = gr.Textbox(label="Output")
36
+
37
+ btn_submit.click(ocr_model, inputs=[image], outputs=text, api_name="PaddleOCR")
38
+ btn_clear.add(text)
39
+
40
+ gr.Markdown(article)
41
+
42
+ if __name__ == '__main__':
43
+ demo.launch(share=True)