Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pickle
|
|
| 5 |
from PIL import Image, ImageDraw
|
| 6 |
import numpy as np
|
| 7 |
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
|
|
|
|
| 8 |
from scipy.ndimage import center_of_mass
|
| 9 |
|
| 10 |
def combine_ims(im1, im2, val=128):
|
|
@@ -44,7 +45,7 @@ def get_out_image(image, predicted_semantic_map):
|
|
| 44 |
extracted_tags = []
|
| 45 |
for id, (y, x) in class_centers.items():
|
| 46 |
class_name = str(class_names[id - 1])
|
| 47 |
-
extracted_tags.append(
|
| 48 |
draw.text((x, y), class_name, fill='black')
|
| 49 |
|
| 50 |
return image_mask, extracted_tags
|
|
@@ -73,7 +74,7 @@ model.eval()
|
|
| 73 |
demo = gr.Interface(
|
| 74 |
gradio_process,
|
| 75 |
inputs=gr.inputs.Image(type="pil"),
|
| 76 |
-
outputs=[gr.outputs.Image(type="pil"), gr.outputs.
|
| 77 |
title="Semantic Segmentation",
|
| 78 |
examples=glob.glob('./examples/*.jpg'),
|
| 79 |
allow_flagging="never",
|
|
|
|
| 5 |
from PIL import Image, ImageDraw
|
| 6 |
import numpy as np
|
| 7 |
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
|
| 8 |
+
|
| 9 |
from scipy.ndimage import center_of_mass
|
| 10 |
|
| 11 |
def combine_ims(im1, im2, val=128):
|
|
|
|
| 45 |
extracted_tags = []
|
| 46 |
for id, (y, x) in class_centers.items():
|
| 47 |
class_name = str(class_names[id - 1])
|
| 48 |
+
extracted_tags.append({"class_name": class_name, "coordinates": (x, y)})
|
| 49 |
draw.text((x, y), class_name, fill='black')
|
| 50 |
|
| 51 |
return image_mask, extracted_tags
|
|
|
|
| 74 |
demo = gr.Interface(
|
| 75 |
gradio_process,
|
| 76 |
inputs=gr.inputs.Image(type="pil"),
|
| 77 |
+
outputs=[gr.outputs.Image(type="pil"), gr.outputs.JSON()],
|
| 78 |
title="Semantic Segmentation",
|
| 79 |
examples=glob.glob('./examples/*.jpg'),
|
| 80 |
allow_flagging="never",
|