File size: 3,848 Bytes
4416234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bd703a
4416234
 
 
5bd703a
4416234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import gradio as gr
import requests as r
from PIL import Image
from io import BytesIO

WARBOY_API_URL = "https://serving.furiosa.in/ocr/v1/image:annotate"
IMAGE_FORMAT = "JPEG"


def convert_image_to_binary(image: Image):
    buf = BytesIO()
    image.save(buf, format=IMAGE_FORMAT)
    return buf.getvalue()


def predict_with_warboy(image):
    binary_image = convert_image_to_binary(image)
    files = {"image": binary_image}

    response = r.post(WARBOY_API_URL, files=files)
    json_response = response.json()

    ocr_lines = [
        line
        for block in json_response["annotation"]["blocks"]
        for paragraph in block["paragraphs"]
        for line in paragraph["lines"]
    ]
    res = []
    for lines in ocr_lines:
        temp_line = []
        for words in lines["words"]:
            temp_line.append(words["data"])
        res.append(" ".join(temp_line))

    return res


css = """
        a {
            color: inherit;
            text-decoration: underline;
        }
        .gradio-container {
            font-family: 'IBM Plex Sans', sans-serif;
        }
        .container {
            max-width: 730px;
            margin: auto;
            padding-top: 1.5rem;
        }
        .gr-box {
            display:flex;
            gap: 1rem;
            flex-direction: column;
            line-height: 1.5;
        }
"""

examples = ["examples/example_1.png", "examples/example_2.png", "examples/example_3.png"]

block = gr.Blocks(css=css)

with block:
    gr.HTML(
        """
            <div style="text-align: center; max-width: 850px; margin: 0 auto;">
              <div>
                <img class="logo" src="https://huggingface.co/datasets/philschmid/assets/resolve/main/furiosa_logo.png" alt="Furiosa AI Logo"
                    style="margin: auto; max-width: 14rem;">
                <h1 style="font-weight: 900; font-size: 2rem;">
                  Furiosa AI <span style="color:#620102;">WARBOY</span>: OCR Demo
                </h1>
              </div>
              <p style="margin-bottom: 10px">
              High performance inference chip for the most advanced vision applications, Edge servers to data centers.
              </p>
               <a href="https://www.furiosa.ai/">Learn more</a>
            </div>
        """
    )

    with gr.Box():
        input_image = gr.Image(label="OCR Image", type="pil", elem_id="img_1")
        gr.Examples(examples=examples, inputs=[input_image])
        furiosa_ocr = gr.Button("Extract Text").style(margin=True, full_width=True)
        furiosa_result = gr.Textbox(label="FuriosaAI Result", lines=2, elem_id="furiosa_result")
        # intel_result = gr.Textbox(label="Intel Result", lines=5, elem_id="furiosa_result")

    furiosa_ocr.click(
        fn=predict_with_warboy,
        inputs=[input_image],
        outputs=furiosa_result,
    )

    gr.HTML(
        """
            <div style="margin: 0 auto">
            <h2 style="font-weight: 900; font-size: 2rem;">What is WARBOY?</h2>
                <p>
                  WARBOY is currently deployed in commercial applications, in public datacenter environments (Kakao Enterprise). Applications include Korea's largest online English education provider ePopSoft's dictionary OCR service. With seamless integration from datacenter hardware to real-time application, FuriosaAI's full-stack solution allows customers to optimize development and operation workstreams and costs, while drastically improving service quality and management experience.
                </p>
              <div>
                <img class="logo" src="https://huggingface.co/datasets/philschmid/assets/resolve/main/furiosa_architecture.png" alt="Furiosa OCR Setup"
                    style="margin: auto; max-width:32rem;">
              </div>
            </div>
        """
    )
block.launch(debug=True)