File size: 2,879 Bytes
93a5bb0
0e2fa7c
 
 
 
 
 
 
 
 
 
 
 
2e927d8
0e2fa7c
 
 
 
 
8cc8dd0
 
 
 
afea2bf
 
805a2d5
2020ffa
 
 
 
 
805a2d5
2020ffa
 
 
8cc8dd0
 
 
 
0e2fa7c
 
 
 
 
 
 
577abd4
 
 
 
 
daf8b84
577abd4
 
2992e49
577abd4
85f6a91
577abd4
 
0e2fa7c
 
 
 
 
 
 
 
 
8cc8dd0
0e2fa7c
 
 
daf8b84
0e2fa7c
 
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
import os
import sys
import cv2
import base64
import gradio as gr
import requests
import numpy as np
import configparser


def run(file):
    in_image = cv2.imread(file)

    encode_img = cv2.imencode('.jpg', in_image)[1].tobytes()
    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'
    payload = {'image': base64_img}
    image_request = requests.post(url, json=payload)

    out_img = image_request.json()['image']
    door_json = image_request.json()['doors']
    wall_json = image_request.json()['walls']
    room_json = image_request.json()['rooms']
    area = image_request.json()['area']
    perimeter = image_request.json()['perimeter']
    out_json = {
        'doors': door_json, 
        'walls': wall_json,
        'rooms': room_json,
        'area': area,
        'perimeter': perimeter
    }

    decode_img = base64.b64decode(out_img.split(',')[1])
    decode_img = np.frombuffer(decode_img, dtype=np.uint8)
    out_img = cv2.imdecode(decode_img, flags=cv2.IMREAD_COLOR)

    return out_img, out_json


with gr.Blocks() as demo:
    gr.Markdown(
        """
        # Floor Plan Recognition
        by [Rasterscan](https://rasterscan.com/)
        
        ## About Us
        RasterScan stands at the forefront of innovation in the realm of architectural and interior design, revolutionizing the way professionals and enthusiasts alike visualize and create spaces. Specializing in floor plan recognition and design, RasterScan harnesses the power of cutting-edge technology to transform blueprints, hand-sketches, and existing floor plans into immersive, three-dimensional models.
        </br>Please ❤️ this space
        
        ## Contact
    
        <a target="_blank" href="mailto:contact@rasterscan.com"><img src="https://img.shields.io/badge/email-contact@rasterscan.com-blue.svg?logo=gmail " alt="rasterscan.com"></a>&emsp;
    
        """
        )

    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.Image(type="numpy"), gr.JSON()]

        start_button.click(run, inputs=app_input, outputs=app_output)

    gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FRasterScan%2FAutomated-Floor-Plan-Digitalization"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FRasterScan%2FAutomated-Floor-Plan-Digitalization&label=Visitors&countColor=%2337d67a" /></a>')

demo.launch()