Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
import pandas as pd
|
|
|
2 |
from PIL import Image
|
3 |
from PIL import ImageDraw
|
4 |
import gradio as gr
|
5 |
import torch
|
6 |
import easyocr
|
7 |
-
import logging
|
8 |
-
logging.basicConfig(level=logging.DEBUG)
|
9 |
|
10 |
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'english.png')
|
11 |
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/thai.jpg', 'thai.jpg')
|
@@ -23,23 +22,11 @@ def draw_boxes(image, bounds, color='yellow', width=2):
|
|
23 |
return image
|
24 |
|
25 |
def inference(img, lang):
|
26 |
-
print(img.name)
|
27 |
-
print(lang)
|
28 |
reader = easyocr.Reader(lang, gpu=False)
|
29 |
-
|
30 |
-
try:
|
31 |
-
bounds = reader.readtext(img.name)
|
32 |
-
except:
|
33 |
-
import traceback
|
34 |
-
traceback.print_exc()
|
35 |
-
print('recognized')
|
36 |
-
print(bounds)
|
37 |
im = PIL.Image.open(img.name)
|
38 |
-
print('start bb')
|
39 |
draw_boxes(im, bounds)
|
40 |
-
print('end bb')
|
41 |
im.save('result.jpg')
|
42 |
-
print('file saved')
|
43 |
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
44 |
|
45 |
title = 'EasyOCR'
|
|
|
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/JaidedAI/EasyOCR/raw/master/examples/english.png', 'english.png')
|
10 |
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/thai.jpg', 'thai.jpg')
|
|
|
22 |
return image
|
23 |
|
24 |
def inference(img, lang):
|
|
|
|
|
25 |
reader = easyocr.Reader(lang, gpu=False)
|
26 |
+
bounds = reader.readtext(img.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
im = PIL.Image.open(img.name)
|
|
|
28 |
draw_boxes(im, bounds)
|
|
|
29 |
im.save('result.jpg')
|
|
|
30 |
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
31 |
|
32 |
title = 'EasyOCR'
|