Spaces:
Sleeping
Sleeping
code clean up
Browse files- README.md +1 -1
- app.py +0 -13
- requirements.txt +0 -1
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Donut
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
|
|
1 |
---
|
2 |
+
title: Donut for Chinese Invoice
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
app.py
CHANGED
@@ -5,11 +5,8 @@ import gradio as gr
|
|
5 |
import torch
|
6 |
from PIL import Image
|
7 |
|
8 |
-
print("test1")
|
9 |
processor = DonutProcessor.from_pretrained("ewfian/donut_cn_invoice")
|
10 |
-
print("test2")
|
11 |
model = VisionEncoderDecoderModel.from_pretrained("ewfian/donut_cn_invoice")
|
12 |
-
print("test3")
|
13 |
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
model.to(device)
|
@@ -17,17 +14,10 @@ model.to(device)
|
|
17 |
task_prompt = "<s_totalAmountInWords>"
|
18 |
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt").input_ids
|
19 |
|
20 |
-
print("test")
|
21 |
-
print(decoder_input_ids.shape)
|
22 |
-
|
23 |
def process_document(image):
|
24 |
-
print("test2")
|
25 |
|
26 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
27 |
|
28 |
-
print(pixel_values.shape)
|
29 |
-
print(pixel_values)
|
30 |
-
|
31 |
outputs = model.generate(
|
32 |
pixel_values.to(device),
|
33 |
decoder_input_ids=decoder_input_ids.to(device),
|
@@ -44,9 +34,6 @@ def process_document(image):
|
|
44 |
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
45 |
return processor.token2json(sequence)
|
46 |
|
47 |
-
# t = process_document(test_sample)
|
48 |
-
# print(t)
|
49 |
-
|
50 |
demo = gr.Interface(
|
51 |
fn=process_document,
|
52 |
inputs="image",
|
|
|
5 |
import torch
|
6 |
from PIL import Image
|
7 |
|
|
|
8 |
processor = DonutProcessor.from_pretrained("ewfian/donut_cn_invoice")
|
|
|
9 |
model = VisionEncoderDecoderModel.from_pretrained("ewfian/donut_cn_invoice")
|
|
|
10 |
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
model.to(device)
|
|
|
14 |
task_prompt = "<s_totalAmountInWords>"
|
15 |
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt").input_ids
|
16 |
|
|
|
|
|
|
|
17 |
def process_document(image):
|
|
|
18 |
|
19 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
20 |
|
|
|
|
|
|
|
21 |
outputs = model.generate(
|
22 |
pixel_values.to(device),
|
23 |
decoder_input_ids=decoder_input_ids.to(device),
|
|
|
34 |
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
35 |
return processor.token2json(sequence)
|
36 |
|
|
|
|
|
|
|
37 |
demo = gr.Interface(
|
38 |
fn=process_document,
|
39 |
inputs="image",
|
requirements.txt
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
sentencepiece==0.1.99
|
2 |
transformers==4.35.0
|
3 |
protobuf==4.23.4
|
4 |
-
gradio<4.0
|
5 |
-f https://download.pytorch.org/whl/torch_stable.html
|
6 |
torch==2.1.0+cpu
|
7 |
-f https://download.pytorch.org/whl/torch_stable.html
|
|
|
1 |
sentencepiece==0.1.99
|
2 |
transformers==4.35.0
|
3 |
protobuf==4.23.4
|
|
|
4 |
-f https://download.pytorch.org/whl/torch_stable.html
|
5 |
torch==2.1.0+cpu
|
6 |
-f https://download.pytorch.org/whl/torch_stable.html
|