soluma commited on
Commit
747b84a
·
verified ·
1 Parent(s): 035ccb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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 the 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):
10
- # Open and preprocess the image
11
- image = Image.open(image).convert("RGB")
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="file"),
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
  )