Spaces:
Runtime error
Runtime error
File size: 1,468 Bytes
0445b72 3f03254 0445b72 6628404 734bc82 6628404 0445b72 3f03254 0445b72 734bc82 0445b72 c690508 0445b72 8f6282a 0445b72 3036475 0445b72 3036475 3f03254 6628404 3f03254 0445b72 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import gradio as gr
import pandas as pd
import easyocr
import torch
import PIL
from PIL import Image
from PIL import ImageDraw
ocr_lang=[
'abq',
'ady',
'af',
'ang',
'ar',
'as',
'ava',
'az',
'be',
'bg',
'bh',
'bho',
'bn',
'bs',
'ch_sim',
'ch_tra',
'che',
'cs',
'cy',
'da',
'dar',
'de',
'en',
'es',
'et',
'fa',
'fr',
'ga',
'gom',
'hi',
'hr',
'hu',
'id',
'inh',
'is',
'it',
'ja',
'kbd',
'kn',
'ko',
'ku',
'la',
'lbe',
'lez',
'lt',
'lv',
'mah',
'mai',
'mi',
'mn',
'mr',
'ms',
'mt',
'ne',
'new',
'nl',
'no',
'oc',
'pi',
'pl',
'pt',
'ro',
'ru',
'rs_cyrillic',
'rs_latin',
'sck',
'sk',
'sl',
'sq',
'sv',
'sw',
'ta',
'tab',
'te',
'th',
'tjk',
'tl',
'tr',
'ug',
'uk',
'ur',
'uz',
'vi',
]
def draw_boxes(image, bounds, color='blue', width=1):
draw = ImageDraw.Draw(image)
for bound in bounds:
p0, p1, p2, p3 = bound[0]
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
return image
def detect(img, lang=[ocr_lang,'en']):
reader = easyocr.Reader(lang)
bounds = reader.readtext(img)
im = PIL.Image.open(img)
im_out=draw_boxes(im, bounds)
return im_out,pd.DataFrame(bounds).iloc[: 0, -1:],pd.DataFrame(bounds).iloc[: 0, -1:]
with gr.Blocks() as robot:
im=gr.Image(type="filepath")
go_btn=gr.Button()
out_im=gr.Image()
with gr.Row():
out_txt=gr.Textbox(lines=8)
data_f=gr.Dataframe()
go_btn.click(detect,im,[out_im,out_txt,data_f])
robot.queue(concurrency_count=10).launch() |