|
|
|
import subprocess |
|
import gradio as gr |
|
from src.task import ocr_task |
|
|
|
|
|
|
|
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True) |
|
|
|
|
|
image = gr.Image(type="pil", label="Image") |
|
|
|
|
|
ocr_text_output = gr.Textbox(label="OCR Text") |
|
ocr_image_output = gr.Image(type="pil", label="Output Image") |
|
|
|
|
|
examples = [ |
|
["images/ocr_image_1jpg"], |
|
["images/ocr_image_2.jpg"], |
|
["images/ocr_image_3.jpg"], |
|
] |
|
|
|
|
|
title = "OCR Text Extraction and Visualization" |
|
description = "Gradio Demo for the Florence-2-large Vision Language Model. This application performs Optical Character Recognition (OCR) on images and provides both extracted text and visualized bounding boxes around detected text regions. To use it, simply upload your image and click 'Submit'. The application will return the detected text and an image with bounding boxes drawn around the detected text regions. This is useful for various OCR-related tasks including document digitization, text extraction, and visual verification of detected text regions." |
|
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2311.06242' target='_blank'>Florence-2: Advancing a Unified Representation for a Variety of Vision Tasks</a> | <a href='https://huggingface.co/microsoft/Florence-2-large-ft' target='_blank'>Model Page</a></p>" |
|
|
|
|
|
|
|
interface = gr.Interface( |
|
fn=ocr_task, |
|
inputs=[image], |
|
outputs=[ocr_image_output, ocr_text_output], |
|
examples=examples, |
|
title=title, |
|
description=description, |
|
article=article, |
|
theme="soft", |
|
allow_flagging="never", |
|
) |
|
interface.launch(debug=False) |
|
|