import spaces import gradio as gr from extractors.idefics2json.receipt_extractor import ReceiptExtractor from indexify_extractor_sdk import Content receipt_extractor = ReceiptExtractor() @spaces.GPU def img2json(image_filepath): if image_filepath is None: raise gr.Error("Please provide some input image: either upload an image file or use the camera") with open(image_filepath, "rb") as f: image_data = f.read() content = Content(content_type="image/jpg", data=image_data) result = receipt_extractor.extract(content) text_content = next(content.data.decode('utf-8') for content in result) return text_content with gr.Blocks( title="Finetuned Idefics2 for Image to JSON with Indexify" ) as receipt_demo: gr.HTML("
Indexify is a scalable realtime and continuous indexing and structured extraction engine for unstructured data to build generative AI applications
") gr.HTML("Step 1: Upload an image file or capture with your camera.
" "Use this demo for single image file only. " "You can extract from image files continuously and try various other extractors locally with " "Indexify.
" ) image_file = gr.Image(sources=["webcam", "upload"], type="filepath") with gr.Column(): gr.HTML("Step 2: Run the extractor.
") go_button = gr.Button( value="Run extractor", variant="primary", # make "primary" so it stands out (default is "secondary") ) model_output_text_box = gr.Textbox( label="Extractor Output", elem_id="model_output_text_box", ) with gr.Row(): gr.HTML( "" "Developed with 🫶 by Indexify | " "a Tensorlake product" "
" ) go_button.click( fn=img2json, inputs = [image_file], outputs = [model_output_text_box] ) demo = gr.TabbedInterface([receipt_demo], ["Receipt Extraction"], theme=gr.themes.Soft()) demo.queue() demo.launch()