Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,13 @@ import gradio as gr
|
|
2 |
from transformers import LayoutLMv3Processor, LayoutLMv3ForTokenClassification
|
3 |
from PIL import Image
|
4 |
|
5 |
-
# Load
|
6 |
processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base")
|
7 |
model = LayoutLMv3ForTokenClassification.from_pretrained("microsoft/layoutlmv3-base", num_labels=5)
|
8 |
|
9 |
-
def extract_invoice_data(
|
10 |
-
# Open
|
11 |
-
image = Image.open(
|
12 |
encoding = processor(image, return_tensors="pt")
|
13 |
outputs = model(**encoding)
|
14 |
predictions = outputs.logits.argmax(-1).squeeze().tolist()
|
@@ -17,7 +17,7 @@ def extract_invoice_data(image):
|
|
17 |
# Update Gradio interface
|
18 |
interface = gr.Interface(
|
19 |
fn=extract_invoice_data,
|
20 |
-
inputs=gr.Image(type="
|
21 |
outputs="json",
|
22 |
title="Invoice Data Extraction"
|
23 |
)
|
|
|
2 |
from transformers import LayoutLMv3Processor, LayoutLMv3ForTokenClassification
|
3 |
from PIL import Image
|
4 |
|
5 |
+
# Load processor and model
|
6 |
processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base")
|
7 |
model = LayoutLMv3ForTokenClassification.from_pretrained("microsoft/layoutlmv3-base", num_labels=5)
|
8 |
|
9 |
+
def extract_invoice_data(image_path):
|
10 |
+
# Open the image from the file path
|
11 |
+
image = Image.open(image_path).convert("RGB")
|
12 |
encoding = processor(image, return_tensors="pt")
|
13 |
outputs = model(**encoding)
|
14 |
predictions = outputs.logits.argmax(-1).squeeze().tolist()
|
|
|
17 |
# Update Gradio interface
|
18 |
interface = gr.Interface(
|
19 |
fn=extract_invoice_data,
|
20 |
+
inputs=gr.Image(type="filepath"), # Use 'filepath' instead of 'file'
|
21 |
outputs="json",
|
22 |
title="Invoice Data Extraction"
|
23 |
)
|