Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -206,8 +206,15 @@ def draw_boxes(image, bounds, color='blue', width=1):
|
|
| 206 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
| 207 |
return image
|
| 208 |
|
| 209 |
-
def detect(img, target_lang):
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
reader = easyocr.Reader(lang)
|
| 212 |
bounds = reader.readtext(img)
|
| 213 |
im = PIL.Image.open(img)
|
|
@@ -215,12 +222,14 @@ def detect(img, target_lang):
|
|
| 215 |
return im_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
|
| 216 |
with gr.Blocks() as robot:
|
| 217 |
im=gr.Image(type="filepath")
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
|
| 220 |
go_btn=gr.Button()
|
| 221 |
out_im=gr.Image()
|
| 222 |
with gr.Row():
|
| 223 |
out_txt=gr.Textbox(lines=8)
|
| 224 |
data_f=gr.Dataframe()
|
| 225 |
-
go_btn.click(detect,[im,target_lang],[out_im,out_txt,data_f])
|
| 226 |
robot.queue(concurrency_count=10).launch()
|
|
|
|
| 206 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
| 207 |
return image
|
| 208 |
|
| 209 |
+
def detect(img, target_lang,target_lang2=None):
|
| 210 |
+
if target_lang2 != None:
|
| 211 |
+
lang=lang_id[target_lang]
|
| 212 |
+
lang2=lang_id[target_lang2]
|
| 213 |
+
lang=[f"{lang},{lang2}"]
|
| 214 |
+
else:
|
| 215 |
+
lang=[f"{lang_id[target_lang]}"]
|
| 216 |
+
|
| 217 |
+
|
| 218 |
reader = easyocr.Reader(lang)
|
| 219 |
bounds = reader.readtext(img)
|
| 220 |
im = PIL.Image.open(img)
|
|
|
|
| 222 |
return im_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
|
| 223 |
with gr.Blocks() as robot:
|
| 224 |
im=gr.Image(type="filepath")
|
| 225 |
+
with gr.Row():
|
| 226 |
+
target_lang = gr.Dropdown(label="Detect language", choices=list(lang_id.keys()),value="English")
|
| 227 |
+
target_lang2 = gr.Dropdown(label="Detect language", choices=list(lang_id.keys()),value="English")
|
| 228 |
|
| 229 |
go_btn=gr.Button()
|
| 230 |
out_im=gr.Image()
|
| 231 |
with gr.Row():
|
| 232 |
out_txt=gr.Textbox(lines=8)
|
| 233 |
data_f=gr.Dataframe()
|
| 234 |
+
go_btn.click(detect,[im,target_lang,target_lang2],[out_im,out_txt,data_f])
|
| 235 |
robot.queue(concurrency_count=10).launch()
|