Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,12 @@
|
|
1 |
-
from
|
2 |
-
from sroie_inference import prediction as sroie_prediction
|
3 |
import gradio as gr
|
4 |
import json
|
5 |
|
6 |
def prediction(image):
|
7 |
|
8 |
-
|
9 |
-
# on the image, which returns a JSON with some info and an image with the corresponding boxes blurred
|
10 |
-
j1, image_blurred = sroie_prediction(image)
|
11 |
-
|
12 |
-
# then use the model fine-tuned on cord on the blurred image
|
13 |
-
img = image_blurred.copy()
|
14 |
-
j2, image_final = cord_prediction(img)
|
15 |
|
16 |
-
|
17 |
-
if len(j1) == 0:
|
18 |
-
j3 = j2
|
19 |
-
else:
|
20 |
-
j3 = json.dumps(j1).split('}')[0] + ', ' + json.dumps(j2).split('{')[1]
|
21 |
-
|
22 |
-
return j1, image_blurred, j2, image_final, j3
|
23 |
|
24 |
|
25 |
title = "Interactive demo: LayoutLMv3 for receipts"
|
@@ -32,10 +19,7 @@ css = """.output_image, .input_image {height: 600px !important}"""
|
|
32 |
# for now it shows also the intermediate steps
|
33 |
iface = gr.Interface(fn=prediction,
|
34 |
inputs=gr.Image(type="pil"),
|
35 |
-
outputs=[gr.
|
36 |
-
gr.Image(type="pil", label="blurred image"),
|
37 |
-
gr.JSON(label="cord parsing"),
|
38 |
-
gr.Image(type="pil", label="annotated image"),
|
39 |
gr.JSON(label="final output")],
|
40 |
title=title,
|
41 |
description=description,
|
|
|
1 |
+
from inference import prediction as cord_sroie_prediction
|
|
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
|
5 |
def prediction(image):
|
6 |
|
7 |
+
j2, image_final = cord_sroie_prediction(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
return j2, image_final
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
title = "Interactive demo: LayoutLMv3 for receipts"
|
|
|
19 |
# for now it shows also the intermediate steps
|
20 |
iface = gr.Interface(fn=prediction,
|
21 |
inputs=gr.Image(type="pil"),
|
22 |
+
outputs=[gr.Image(type="pil", label="annotated image"),
|
|
|
|
|
|
|
23 |
gr.JSON(label="final output")],
|
24 |
title=title,
|
25 |
description=description,
|