radames commited on
Commit
ead9ffa
β€’
1 Parent(s): a15d96e

possible avoiding file clashing

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -7,6 +7,7 @@ import cv2
7
  import PIL
8
  import sys
9
  import os
 
10
  from PIL import ImageFont, ImageDraw, Image
11
  this=gr.Interface.load("spaces/Omnibus/Translate-100")
12
 
@@ -234,13 +235,14 @@ def detect(img, target_lang,trans_lang,ocr_sens,font_fac,target_lang2=None):
234
 
235
  img = Image.open(img)
236
  img.thumbnail((1000,1000), Image.Resampling.LANCZOS)
237
- img.save("tmp.jpg")
 
238
  img1 = np.array(img)
239
  reader = easyocr.Reader(lang)
240
  bounds = reader.readtext(img1)
241
- im = PIL.Image.open("tmp.jpg")
242
  im_out=draw_boxes(im, bounds,ocr_sens)
243
- blr_out=blur_im("tmp.jpg",bounds,target_lang,trans_lang,ocr_sens,font_fac)
244
  return im_out,blr_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
245
 
246
  with gr.Blocks() as robot:
 
7
  import PIL
8
  import sys
9
  import os
10
+ import uuid
11
  from PIL import ImageFont, ImageDraw, Image
12
  this=gr.Interface.load("spaces/Omnibus/Translate-100")
13
 
 
235
 
236
  img = Image.open(img)
237
  img.thumbnail((1000,1000), Image.Resampling.LANCZOS)
238
+ path = f"/tmp/{uuid.uuid4()}.jpg"
239
+ img.save(path)
240
  img1 = np.array(img)
241
  reader = easyocr.Reader(lang)
242
  bounds = reader.readtext(img1)
243
+ im = PIL.Image.open(path)
244
  im_out=draw_boxes(im, bounds,ocr_sens)
245
+ blr_out=blur_im(path,bounds,target_lang,trans_lang,ocr_sens,font_fac)
246
  return im_out,blr_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
247
 
248
  with gr.Blocks() as robot: