Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ os.system("wget https://i.imgur.com/fSL1CGG.jpg")
|
|
14 |
os.environ["PYTHONPATH"]=os.environ["PYTHONPATH"]+":"+f"{os.getcwd()}/src/text_recognition/deep-text-recognition-benchmark"
|
15 |
|
16 |
import gradio as gr
|
|
|
17 |
from uuid import uuid4
|
18 |
from pathlib import Path
|
19 |
|
@@ -23,8 +24,17 @@ def inference(im):
|
|
23 |
Path(f'{dir_name}/img').mkdir(parents=True)
|
24 |
im.save(f'{dir_name}/img/image.jpg')
|
25 |
os.system(f'python main.py infer {dir_name}/img/image.jpg {dir_name}_output -s f -i')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
with open(f'{dir_name}_output/image/txt/image_main.txt') as f:
|
27 |
-
return
|
28 |
|
29 |
title = "NDLOCR"
|
30 |
description = "Gradio demo for NDLOCR. NDLOCR is a text recognition (OCR) Program."
|
|
|
14 |
os.environ["PYTHONPATH"]=os.environ["PYTHONPATH"]+":"+f"{os.getcwd()}/src/text_recognition/deep-text-recognition-benchmark"
|
15 |
|
16 |
import gradio as gr
|
17 |
+
from PIL import Image
|
18 |
from uuid import uuid4
|
19 |
from pathlib import Path
|
20 |
|
|
|
24 |
Path(f'{dir_name}/img').mkdir(parents=True)
|
25 |
im.save(f'{dir_name}/img/image.jpg')
|
26 |
os.system(f'python main.py infer {dir_name}/img/image.jpg {dir_name}_output -s f -i')
|
27 |
+
image_path = f'{dir_name}_output/image/pred_img/image_L.jpg'
|
28 |
+
if Path(f'{dir_name}_output/image/pred_img/image_R.jpg').exists():
|
29 |
+
image_L = Image.open(f'{dir_name}_output/image/pred_img/image_L.jpg')
|
30 |
+
image_R = Image.open(f'{dir_name}_output/image/pred_img/image_R.jpg')
|
31 |
+
dst = Image.new('RGB', (image_L.width + image_R.width, image_L.height))
|
32 |
+
dst.paste(image_L, (0, 0))
|
33 |
+
dst.paste(image_R, (image_L.width, 0))
|
34 |
+
dst.save(f'{dir_name}_output/image/pred_img/image_LR.jpg')
|
35 |
+
image_path = f'{dir_name}_output/image/pred_img/image_LR.jpg'
|
36 |
with open(f'{dir_name}_output/image/txt/image_main.txt') as f:
|
37 |
+
return image_path, f.read()
|
38 |
|
39 |
title = "NDLOCR"
|
40 |
description = "Gradio demo for NDLOCR. NDLOCR is a text recognition (OCR) Program."
|