crazyai-kby
commited on
Commit
·
8cc8dd0
1
Parent(s):
817e8a9
v1
Browse files
app.py
CHANGED
|
@@ -9,12 +9,6 @@ import configparser
|
|
| 9 |
|
| 10 |
|
| 11 |
def run(file):
|
| 12 |
-
backend_url = os.getenv('BACKEND_URL')
|
| 13 |
-
url = f'{backend_url}/raster-to-vector-base64'
|
| 14 |
-
out_json = {'json': url}
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return out_json
|
| 18 |
in_image = cv2.imread(file)
|
| 19 |
|
| 20 |
encode_img = cv2.imencode('.jpg', in_image)[1].tostring()
|
|
@@ -23,17 +17,15 @@ def run(file):
|
|
| 23 |
|
| 24 |
backend_url = os.getenv('BACKEND_URL')
|
| 25 |
url = f'{backend_url}/raster-to-vector-base64'
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
# decode_img = np.frombuffer(decode_img, dtype=np.uint8)
|
| 36 |
-
# out_img = cv2.imdecode(decode_img, flags=cv2.IMREAD_COLOR)
|
| 37 |
|
| 38 |
return out_img, out_json
|
| 39 |
|
|
@@ -54,7 +46,7 @@ with gr.Blocks() as demo:
|
|
| 54 |
inputs=app_input)
|
| 55 |
start_button = gr.Button("Run")
|
| 56 |
with gr.Column():
|
| 57 |
-
app_output = [gr.JSON()]
|
| 58 |
|
| 59 |
start_button.click(run, inputs=app_input, outputs=app_output)
|
| 60 |
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def run(file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
in_image = cv2.imread(file)
|
| 13 |
|
| 14 |
encode_img = cv2.imencode('.jpg', in_image)[1].tostring()
|
|
|
|
| 17 |
|
| 18 |
backend_url = os.getenv('BACKEND_URL')
|
| 19 |
url = f'{backend_url}/raster-to-vector-base64'
|
| 20 |
+
payload = {'image': base64_img}
|
| 21 |
+
image_request = requests.post(url, json=payload)
|
| 22 |
+
|
| 23 |
+
out_img = image_request.json()['image']
|
| 24 |
+
out_json = image_request.json()['graph']
|
| 25 |
+
|
| 26 |
+
decode_img = base64.b64decode(out_img.split(',')[1])
|
| 27 |
+
decode_img = np.frombuffer(decode_img, dtype=np.uint8)
|
| 28 |
+
out_img = cv2.imdecode(decode_img, flags=cv2.IMREAD_COLOR)
|
|
|
|
|
|
|
| 29 |
|
| 30 |
return out_img, out_json
|
| 31 |
|
|
|
|
| 46 |
inputs=app_input)
|
| 47 |
start_button = gr.Button("Run")
|
| 48 |
with gr.Column():
|
| 49 |
+
app_output = [gr.Image(type="numpy"), gr.JSON()]
|
| 50 |
|
| 51 |
start_button.click(run, inputs=app_input, outputs=app_output)
|
| 52 |
|