File size: 1,786 Bytes
dbfc97a
338d325
 
a1328ad
dbfc97a
158b8d1
dbfc97a
 
 
 
 
 
e4b6db7
dbfc97a
 
 
 
5033bf7
 
dbfc97a
7c2e9e6
dbfc97a
 
 
 
bcbef50
dbfc97a
 
 
 
 
 
 
 
 
b0ff63f
 
dbfc97a
 
 
9442785
b0ff63f
dbfc97a
0abdd14
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
# Importing the requirements
import warnings
warnings.filterwarnings("ignore")

import gradio as gr
from src.app.task import ocr_task


# Image input for the interface
image = gr.Image(type="pil", label="Image")

# Output for the interface (image and text)
ocr_text_output = gr.Textbox(label="OCR Text", show_label=True, show_copy_button=True)
ocr_image_output = gr.Image(type="pil", label="Output Image")

# Examples for the interface (image paths)
examples = [
    ["images/ocr_image_1.jpg"],
    ["images/ocr_image_2.jpg"],
    ["images/ocr_image_3.jpg"],
    ["images/ocr_image_4.png"]
]

# Title, description, and article for the interface
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. Read more at the links below."
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>"


# Launch the interface
interface = gr.Interface(
    fn=ocr_task,
    inputs=[image],
    outputs=[ocr_image_output, ocr_text_output],
    examples=examples,
    cache_examples=True,
    cache_mode="lazy",
    title=title,
    description=description,
    article=article,
    theme="Nymbo/Nymbo_Theme",
    flagging_mode="never",
)
interface.launch(debug=False)