File size: 1,190 Bytes
631fbf6 f87ad7d 631fbf6 f87ad7d 5c0e0bf e2be7fc 5c0e0bf e069815 5c0e0bf b92f91b 5c0e0bf e2be7fc 5c0e0bf 9aa5d26 f87ad7d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import gradio as gr
import tempfile
from information_extraction import extract_invoice
def process_image(image):
if image is None:
return None
with tempfile.NamedTemporaryFile(suffix='.jpg',delete=True) as tmp:
image.save(tmp.name)
result = extract_invoice(tmp.name)
return result
with gr.Blocks(title="Invoice Extraction with CrewAI") as demo:
gr.Markdown(
"""
# Invoice Information Extraction
Upload an Invoice and get structured JSON
"""
)
with gr.Row():
## Left column upload invoice
with gr.Column(scale=1):
image_input = gr.Image(
type ='pil',
label = "Upload Invoice Image",
height = None,
width = None
)
extract_btn = gr.Button("Extract Invoice", variant="primary")
with gr.Column(scale=1):
output=gr.JSON(label='Extracted Invoice JSOn')
extract_btn.click(
fn=process_image,
inputs=image_input,
outputs=output
)
if __name__=="__main__":
demo.launch()
|