Spaces:
Runtime error
Runtime error
Commit
•
4416234
1
Parent(s):
7875a05
Upload 5 files
Browse files- app.py +109 -0
- examples/example_1.png +0 -0
- examples/example_2.png +0 -0
- examples/example_3.png +0 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests as r
|
3 |
+
from PIL import Image
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
WARBOY_API_URL = "https://serving.furiosa.in/ocr/v1/image:annotate"
|
7 |
+
IMAGE_FORMAT = "JPEG"
|
8 |
+
|
9 |
+
|
10 |
+
def convert_image_to_binary(image: Image):
|
11 |
+
buf = BytesIO()
|
12 |
+
image.save(buf, format=IMAGE_FORMAT)
|
13 |
+
return buf.getvalue()
|
14 |
+
|
15 |
+
|
16 |
+
def predict_with_warboy(image):
|
17 |
+
binary_image = convert_image_to_binary(image)
|
18 |
+
files = {"image": binary_image}
|
19 |
+
|
20 |
+
response = r.post(WARBOY_API_URL, files=files)
|
21 |
+
json_response = response.json()
|
22 |
+
|
23 |
+
ocr_lines = [
|
24 |
+
line
|
25 |
+
for block in json_response["annotation"]["blocks"]
|
26 |
+
for paragraph in block["paragraphs"]
|
27 |
+
for line in paragraph["lines"]
|
28 |
+
]
|
29 |
+
res = []
|
30 |
+
for lines in ocr_lines:
|
31 |
+
temp_line = []
|
32 |
+
for words in lines["words"]:
|
33 |
+
temp_line.append(words["data"])
|
34 |
+
res.append(" ".join(temp_line))
|
35 |
+
|
36 |
+
return res
|
37 |
+
|
38 |
+
|
39 |
+
css = """
|
40 |
+
a {
|
41 |
+
color: inherit;
|
42 |
+
text-decoration: underline;
|
43 |
+
}
|
44 |
+
.gradio-container {
|
45 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
46 |
+
}
|
47 |
+
.container {
|
48 |
+
max-width: 730px;
|
49 |
+
margin: auto;
|
50 |
+
padding-top: 1.5rem;
|
51 |
+
}
|
52 |
+
.gr-box{
|
53 |
+
display:flex;
|
54 |
+
gap: 1rem;
|
55 |
+
flex-direction: column;
|
56 |
+
}
|
57 |
+
"""
|
58 |
+
|
59 |
+
examples = ["examples/example_1.png", "examples/example_2.png", "examples/example_3.png"]
|
60 |
+
|
61 |
+
block = gr.Blocks(css=css)
|
62 |
+
|
63 |
+
with block:
|
64 |
+
gr.HTML(
|
65 |
+
"""
|
66 |
+
<div style="text-align: center; max-width: 850px; margin: 0 auto;">
|
67 |
+
<div>
|
68 |
+
<img class="logo" src="https://huggingface.co/datasets/philschmid/assets/resolve/main/furiosa_logo.png" alt="Furiosa AI Logo"
|
69 |
+
style="margin: auto; max-width: 14rem;">
|
70 |
+
<h1 style="font-weight: 900; font-size: 2rem;">
|
71 |
+
Furiosa AI <span style="color:#620102;">WARBOY</span>: OCR Demo
|
72 |
+
</h1>
|
73 |
+
</div>
|
74 |
+
<p style="margin-bottom: 10px">
|
75 |
+
High performance inference chip for the most advanced vision applications, Edge servers to data centers.
|
76 |
+
</p>
|
77 |
+
<a href="https://www.furiosa.ai/">Learn more</a>
|
78 |
+
</div>
|
79 |
+
"""
|
80 |
+
)
|
81 |
+
|
82 |
+
with gr.Box():
|
83 |
+
input_image = gr.Image(label="OCR Image", type="pil", elem_id="img_1")
|
84 |
+
gr.Examples(examples=examples, inputs=[input_image])
|
85 |
+
furiosa_ocr = gr.Button("Extract Text").style(margin=True, full_width=True)
|
86 |
+
furiosa_result = gr.Textbox(label="FuriosaAI Result", lines=2, elem_id="furiosa_result")
|
87 |
+
# intel_result = gr.Textbox(label="Intel Result", lines=5, elem_id="furiosa_result")
|
88 |
+
|
89 |
+
furiosa_ocr.click(
|
90 |
+
fn=predict_with_warboy,
|
91 |
+
inputs=[input_image],
|
92 |
+
outputs=furiosa_result,
|
93 |
+
)
|
94 |
+
|
95 |
+
gr.HTML(
|
96 |
+
"""
|
97 |
+
<div style="margin: 0 auto">
|
98 |
+
<h2 style="font-weight: 900; font-size: 2rem;">What is WARBOY?</h2>
|
99 |
+
<p>
|
100 |
+
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.
|
101 |
+
</p>
|
102 |
+
<div>
|
103 |
+
<img class="logo" src="https://huggingface.co/datasets/philschmid/assets/resolve/main/furiosa_architecture.png" alt="Furiosa OCR Setup"
|
104 |
+
style="margin: auto; max-width:32rem;">
|
105 |
+
</div>
|
106 |
+
</div>
|
107 |
+
"""
|
108 |
+
)
|
109 |
+
block.launch(debug=True)
|
examples/example_1.png
ADDED
examples/example_2.png
ADDED
examples/example_3.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
gevent
|
3 |
+
grequests
|
4 |
+
gradio
|
5 |
+
pillow
|