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; } """ examples = ["examples/example_1.png", "examples/example_2.png", "examples/example_3.png"] block = gr.Blocks(css=css) with block: gr.HTML( """

Furiosa AI WARBOY: OCR Demo

High performance inference chip for the most advanced vision applications, Edge servers to data centers.

Learn more
""" ) 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( """

What is WARBOY?

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.

""" ) block.launch(debug=True)