awacke1 commited on
Commit
ef1eb47
1 Parent(s): c1748a8

Create backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +64 -0
backupapp.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import PIL
3
+ from PIL import Image
4
+ from PIL import ImageDraw
5
+ import gradio as gr
6
+ import torch
7
+ import easyocr
8
+
9
+ #torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/BeautyIsTruthTruthisBeauty.JPG', 'BeautyIsTruthTruthisBeauty.JPG')
10
+ #torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/PleaseRepeatLouder.jpg', 'PleaseRepeatLouder.jpg')
11
+ #torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/ProhibitedInWhiteHouse.JPG', 'ProhibitedInWhiteHouse.JPG')
12
+
13
+ torch.hub.download_url_to_file('https://raw.githubusercontent.com/AaronCWacker/Yggdrasil/master/images/20-Books.jpg','20-Books.jpg')
14
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'COVID.png')
15
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/chinese.jpg', 'chinese.jpg')
16
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/japanese.jpg', 'japanese.jpg')
17
+ torch.hub.download_url_to_file('https://i.imgur.com/mwQFd7G.jpeg', 'Hindi.jpeg')
18
+
19
+ def draw_boxes(image, bounds, color='yellow', width=2):
20
+ draw = ImageDraw.Draw(image)
21
+ for bound in bounds:
22
+ p0, p1, p2, p3 = bound[0]
23
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
24
+ return image
25
+
26
+ def inference(img, lang):
27
+ reader = easyocr.Reader(lang)
28
+ bounds = reader.readtext(img.name)
29
+ im = PIL.Image.open(img.name)
30
+ draw_boxes(im, bounds)
31
+ im.save('result.jpg')
32
+ return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
33
+
34
+ title = '🖼️Image to Multilingual OCR👁️Gradio'
35
+ description = 'Multilingual OCR which works conveniently on all devices in multiple languages.'
36
+ article = "<p style='text-align: center'></p>"
37
+
38
+ examples = [
39
+ #['PleaseRepeatLouder.jpg',['ja']],['ProhibitedInWhiteHouse.JPG',['en']],['BeautyIsTruthTruthisBeauty.JPG',['en']],
40
+ ['20-Books.jpg',['en']],['COVID.png',['en']],['chinese.jpg',['ch_sim', 'en']],['japanese.jpg',['ja', 'en']],['Hindi.jpeg',['hi', 'en']]
41
+ ]
42
+
43
+ css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
44
+ choices = [
45
+ "ch_sim",
46
+ "ch_tra",
47
+ "de",
48
+ "en",
49
+ "es",
50
+ "ja",
51
+ "hi",
52
+ "ru"
53
+ ]
54
+ gr.Interface(
55
+ inference,
56
+ [gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
57
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
58
+ title=title,
59
+ description=description,
60
+ article=article,
61
+ examples=examples,
62
+ css=css,
63
+ enable_queue=True
64
+ ).launch(debug=True)