Spaces:
Runtime error
Runtime error
possible avoiding file clashing
#2
by
radames
- opened
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 |
-
|
|
|
|
| 238 |
img1 = np.array(img)
|
| 239 |
reader = easyocr.Reader(lang)
|
| 240 |
bounds = reader.readtext(img1)
|
| 241 |
-
im = PIL.Image.open(
|
| 242 |
im_out=draw_boxes(im, bounds,ocr_sens)
|
| 243 |
-
blr_out=blur_im(
|
| 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:
|