|
import os |
|
import sys |
|
import cv2 |
|
import base64 |
|
import gradio as gr |
|
import requests |
|
import numpy as np |
|
import configparser |
|
|
|
|
|
def run(file): |
|
backend_url = os.getenv('BACKEND_URL') |
|
url = f'{backend_url}/raster-to-vector-base64' |
|
out_json = {'json': url} |
|
|
|
|
|
return out_json |
|
in_image = cv2.imread(file) |
|
|
|
encode_img = cv2.imencode('.jpg', in_image)[1].tostring() |
|
encode_img = base64.encodebytes(encode_img) |
|
base64_img = str(encode_img, 'utf-8') |
|
|
|
backend_url = os.getenv('BACKEND_URL') |
|
url = f'{backend_url}/raster-to-vector-base64' |
|
out_json = {'json': url} |
|
out_img = in_image |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return out_img, out_json |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown( |
|
""" |
|
# Raster-To-Vector on Floor Plan images |
|
Please give me star if you like it and reach out to me to get on-premise solutions. (Email: andywu@kby-ai.com) |
|
""" |
|
) |
|
|
|
with gr.TabItem("Floor Plan Recognition"): |
|
with gr.Row(): |
|
with gr.Column(): |
|
app_input = gr.Image(type='filepath') |
|
gr.Examples(['images/1.jpg', 'images/2.png', 'images/3.png', 'images/4.png'], |
|
inputs=app_input) |
|
start_button = gr.Button("Run") |
|
with gr.Column(): |
|
app_output = [gr.JSON()] |
|
|
|
start_button.click(run, inputs=app_input, outputs=app_output) |
|
|
|
|
|
demo.launch() |
|
|