Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,28 +15,30 @@ def demo_process(input_pdf):
|
|
15 |
|
16 |
temp_dir = "images"
|
17 |
basename = os.path.basename(input_pdf).split('.')[0]
|
18 |
-
image_name = basename + "jpg"
|
19 |
os.makedirs(temp_dir, exist_ok=True)
|
20 |
|
21 |
with open(os.path.join(temp_dir, image_name), "wb") as f:
|
22 |
f.write(image_bytes)
|
|
|
|
|
23 |
|
24 |
-
zip_path = "images.zip"
|
25 |
image_path = os.path.join(temp_dir, image_name)
|
26 |
-
|
27 |
-
with zipfile.ZipFile(zip_path, "w") as zipf:
|
28 |
-
|
29 |
|
30 |
os.remove(image_path)
|
31 |
os.rmdir(temp_dir)
|
32 |
|
33 |
-
return
|
34 |
-
|
35 |
-
# task_name = "SGSInvoice"
|
36 |
-
# task_prompt = f"<s_{task_name}>"
|
37 |
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
iface = gr.Interface(
|
42 |
fn=demo_process,
|
|
|
15 |
|
16 |
temp_dir = "images"
|
17 |
basename = os.path.basename(input_pdf).split('.')[0]
|
18 |
+
image_name = basename + ".jpg"
|
19 |
os.makedirs(temp_dir, exist_ok=True)
|
20 |
|
21 |
with open(os.path.join(temp_dir, image_name), "wb") as f:
|
22 |
f.write(image_bytes)
|
23 |
+
|
24 |
+
|
25 |
|
26 |
+
# zip_path = "images.zip"
|
27 |
image_path = os.path.join(temp_dir, image_name)
|
28 |
+
output = model.inference(image=image_path, prompt=task_prompt)["predictions"][0]
|
29 |
+
# with zipfile.ZipFile(zip_path, "w") as zipf:
|
30 |
+
# zipf.write(os.path.join(temp_dir, image_name), image_name)
|
31 |
|
32 |
os.remove(image_path)
|
33 |
os.rmdir(temp_dir)
|
34 |
|
35 |
+
return output
|
36 |
+
|
|
|
|
|
37 |
|
38 |
+
task_name = "SGSInvoice"
|
39 |
+
task_prompt = f"<s_{task_name}>"
|
40 |
+
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
41 |
+
model.eval()
|
42 |
|
43 |
iface = gr.Interface(
|
44 |
fn=demo_process,
|