Spaces:
Sleeping
Sleeping
Commit
·
1a9af2e
1
Parent(s):
04c7187
up
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import torch
|
|
11 |
import random
|
12 |
import io
|
13 |
import base64
|
|
|
14 |
|
15 |
def removeFurniture(input_img1,
|
16 |
input_img2,
|
@@ -55,13 +56,13 @@ def segmentation(img):
|
|
55 |
print("segmentation")
|
56 |
|
57 |
# semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
58 |
-
|
59 |
-
results =
|
60 |
for p in results:
|
61 |
p['mask'] = utils.image_to_byte_array(p['mask'])
|
62 |
-
p['mask'] = base64.b64encode(p['mask'])
|
63 |
#print(results)
|
64 |
-
return
|
65 |
|
66 |
|
67 |
def upscale(image):
|
@@ -91,7 +92,7 @@ with gr.Blocks() as app:
|
|
91 |
gr.Image(),
|
92 |
gr.Image()])
|
93 |
with gr.Column():
|
94 |
-
gr.Button("Segmentation").click(segmentation, inputs=gr.Image(type="pil"), outputs=gr.
|
95 |
with gr.Column():
|
96 |
gr.Button("Upscale").click(upscale, inputs=gr.Image(type="pil"), outputs=gr.Image())
|
97 |
|
|
|
11 |
import random
|
12 |
import io
|
13 |
import base64
|
14 |
+
import json
|
15 |
|
16 |
def removeFurniture(input_img1,
|
17 |
input_img2,
|
|
|
56 |
print("segmentation")
|
57 |
|
58 |
# semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
59 |
+
pipe = pipeline("image-segmentation", "facebook/maskformer-swin-large-ade")
|
60 |
+
results = pipe(img)
|
61 |
for p in results:
|
62 |
p['mask'] = utils.image_to_byte_array(p['mask'])
|
63 |
+
p['mask'] = base64.b64encode(p['mask']).decode("utf-8")
|
64 |
#print(results)
|
65 |
+
return json.dumps(results)
|
66 |
|
67 |
|
68 |
def upscale(image):
|
|
|
92 |
gr.Image(),
|
93 |
gr.Image()])
|
94 |
with gr.Column():
|
95 |
+
gr.Button("Segmentation").click(segmentation, inputs=gr.Image(type="pil"), outputs=gr.JSON())
|
96 |
with gr.Column():
|
97 |
gr.Button("Upscale").click(upscale, inputs=gr.Image(type="pil"), outputs=gr.Image())
|
98 |
|