Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -198,7 +198,13 @@ ocr_lang=[
|
|
198 |
|
199 |
|
200 |
|
|
|
|
|
|
|
201 |
|
|
|
|
|
|
|
202 |
def draw_boxes(image, bounds, color='blue', width=1):
|
203 |
draw = ImageDraw.Draw(image)
|
204 |
for bound in bounds:
|
@@ -214,12 +220,18 @@ def detect(img, target_lang,target_lang2=None):
|
|
214 |
else:
|
215 |
lang=[f"{lang_id[target_lang]}"]
|
216 |
pass
|
217 |
-
|
218 |
reader = easyocr.Reader(lang)
|
219 |
bounds = reader.readtext(img)
|
220 |
im = PIL.Image.open(img)
|
221 |
im_out=draw_boxes(im, bounds)
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
with gr.Blocks() as robot:
|
224 |
with gr.Row():
|
225 |
with gr.Column():
|
@@ -241,5 +253,5 @@ with gr.Blocks() as robot:
|
|
241 |
gr.Column()
|
242 |
|
243 |
|
244 |
-
go_btn.click(detect,[im,target_lang,target_lang2],[out_im,out_txt,data_f])
|
245 |
robot.queue(concurrency_count=10).launch()
|
|
|
198 |
|
199 |
|
200 |
|
201 |
+
def blur_im(img,bounds):
|
202 |
+
for bound in bounds:
|
203 |
+
p0, p1, p2, p3 = bound[0]
|
204 |
|
205 |
+
img[p0, p2] = cv2.blur(img[p0, p2] ,(23,23))
|
206 |
+
return img
|
207 |
+
|
208 |
def draw_boxes(image, bounds, color='blue', width=1):
|
209 |
draw = ImageDraw.Draw(image)
|
210 |
for bound in bounds:
|
|
|
220 |
else:
|
221 |
lang=[f"{lang_id[target_lang]}"]
|
222 |
pass
|
223 |
+
global bounds
|
224 |
reader = easyocr.Reader(lang)
|
225 |
bounds = reader.readtext(img)
|
226 |
im = PIL.Image.open(img)
|
227 |
im_out=draw_boxes(im, bounds)
|
228 |
+
blr_out=blur_im(im,bounds)
|
229 |
+
return im_out,blr_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
|
230 |
+
|
231 |
+
|
232 |
+
|
233 |
+
|
234 |
+
|
235 |
with gr.Blocks() as robot:
|
236 |
with gr.Row():
|
237 |
with gr.Column():
|
|
|
253 |
gr.Column()
|
254 |
|
255 |
|
256 |
+
go_btn.click(detect,[im,target_lang,target_lang2],[out_im,trans_im,out_txt,data_f])
|
257 |
robot.queue(concurrency_count=10).launch()
|