crazyai-kby commited on
Commit
0e2fa7c
·
0 Parent(s):

Add application file

Browse files
Files changed (6) hide show
  1. app.py +53 -0
  2. images/1.jpg +0 -0
  3. images/2.png +0 -0
  4. images/3.png +0 -0
  5. images/4.png +0 -0
  6. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import cv2
3
+ import base64
4
+ import gradio as gr
5
+ import requests
6
+ import numpy as np
7
+ import configparser
8
+
9
+
10
+ def run(file):
11
+ in_image = cv2.imread(file)
12
+
13
+ encode_img = cv2.imencode('.jpg', in_image)[1].tostring()
14
+ encode_img = base64.encodebytes(encode_img)
15
+ base64_img = str(encode_img, 'utf-8')
16
+
17
+ backend_url = os.getenv('BACKEND_URL')
18
+ url = f'{backend_url}/raster-to-vector-base64'
19
+ payload = {'image': base64_img}
20
+ image_request = requests.post(url, json=payload)
21
+
22
+ out_img = image_request.json()['image']
23
+ out_json = image_request.json()['graph']
24
+
25
+ decode_img = base64.b64decode(out_img.split(',')[1])
26
+ decode_img = np.frombuffer(decode_img, dtype=np.uint8)
27
+ out_img = cv2.imdecode(decode_img, flags=cv2.IMREAD_COLOR)
28
+
29
+ return out_img, out_json
30
+
31
+
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown(
34
+ """
35
+ # Raster-To-Vector on Floor Plan images
36
+ Please give me star if you like it and reach out to me to get on-premise solutions. (Whatsapp only: +1 442 229 5661)
37
+ """
38
+ )
39
+
40
+ with gr.TabItem("Floor Plan Recognition"):
41
+ with gr.Row():
42
+ with gr.Column():
43
+ app_input = gr.Image(type='filepath')
44
+ gr.Examples(['images/1.jpg', 'images/2.png', 'images/3.png', 'images/4.png'],
45
+ inputs=app_input)
46
+ start_button = gr.Button("Run")
47
+ with gr.Column():
48
+ app_output = [gr.Image(type="numpy"), gr.JSON()]
49
+
50
+ start_button.click(run, inputs=app_input, outputs=app_output)
51
+
52
+
53
+ demo.launch()
images/1.jpg ADDED
images/2.png ADDED
images/3.png ADDED
images/4.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ opencv-python==4.8.0.74