| import gradio as gr |
| from Backend.OCR.Static.ImageOCR import detect_and_ocr, extract_details_from_validated_output, further_processing,handle_processing |
|
|
| def createStaticOcrInterface(): |
| with gr.Blocks() as ocr_interface: |
| gr.Markdown("# Flipkart Grid Robotics Track - OCR Interface") |
|
|
| with gr.Tabs(): |
| |
| with gr.TabItem("Upload & Detection"): |
| with gr.Row(): |
| input_image = gr.Image(type="pil", label="Upload Image", height=400, width=400) |
| output_image = gr.Image(label="Image with Bounding Boxes", height=400, width=400) |
|
|
| btn = gr.Button("Analyze Image & Extract Text") |
|
|
| |
| with gr.TabItem("OCR Results"): |
| with gr.Row(): |
| extracted_textbox = gr.Textbox(label="Extracted OCR Text", lines=5) |
| with gr.Row(): |
| refined_textbox = gr.Textbox(label="Refined Text from Gemini", lines=5) |
| with gr.Row(): |
| validated_textbox = gr.Textbox(label="Validated Output", lines=5) |
|
|
| |
| with gr.Row(): |
| detail_table = gr.Dataframe( |
| headers=["Label", "Value"], |
| value=[["", ""], ["", ""], ["", ""]], |
| label="Manufacturing, Expiration Dates & MRP", |
| datatype=["str", "str"], |
| interactive=False, |
| ) |
|
|
| further_button = gr.Button("Comprehensive OCR", visible=False) |
|
|
| |
| btn.click( |
| detect_and_ocr, |
| inputs=[input_image], |
| outputs=[output_image, extracted_textbox, refined_textbox, validated_textbox] |
| ) |
|
|
| |
| validated_textbox.change( |
| lambda validated_output: extract_details_from_validated_output(validated_output), |
| inputs=[validated_textbox], |
| outputs=[detail_table] |
| ) |
|
|
| |
| further_button.click( |
| further_processing, |
| inputs=[input_image, extracted_textbox], |
| outputs=refined_textbox |
| ) |
|
|
| |
| refined_textbox.change( |
| handle_processing, |
| inputs=[validated_textbox], |
| outputs=[further_button] |
| ) |
|
|
| further_button.click( |
| lambda: gr.update(visible=False), |
| outputs=[validated_textbox] |
| ) |
|
|
| return ocr_interface |