Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -37,18 +37,27 @@ def visualize_mask(predicted_semantic_map, class_ids, class_colors):
|
|
37 |
return image_mask
|
38 |
|
39 |
def get_out_image(image, predicted_semantic_map):
|
40 |
-
class_centers = get_class_centers(predicted_semantic_map, class_dict)
|
41 |
mask = visualize_mask(predicted_semantic_map, class_ids, class_colors)
|
42 |
image_mask = combine_ims(image, mask, val=128)
|
43 |
draw = ImageDraw.Draw(image_mask)
|
44 |
-
|
45 |
extracted_tags = []
|
46 |
for id, (y, x) in class_centers.items():
|
47 |
class_name = str(class_names[id - 1])
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
draw.text((x, y), class_name, fill='black')
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
|
@@ -76,12 +85,10 @@ model.eval()
|
|
76 |
demo = gr.Interface(
|
77 |
gradio_process,
|
78 |
inputs=gr.inputs.Image(type="pil"),
|
79 |
-
outputs=[gr.outputs.Image(type="pil"), gr.outputs.
|
80 |
title="Semantic Segmentation",
|
81 |
examples=glob.glob('./examples/*.jpg'),
|
82 |
allow_flagging="never",
|
83 |
)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
demo.launch()
|
|
|
37 |
return image_mask
|
38 |
|
39 |
def get_out_image(image, predicted_semantic_map):
|
40 |
+
class_centers = get_class_centers(predicted_semantic_map, class_dict)
|
41 |
mask = visualize_mask(predicted_semantic_map, class_ids, class_colors)
|
42 |
image_mask = combine_ims(image, mask, val=128)
|
43 |
draw = ImageDraw.Draw(image_mask)
|
44 |
+
|
45 |
extracted_tags = []
|
46 |
for id, (y, x) in class_centers.items():
|
47 |
class_name = str(class_names[id - 1])
|
48 |
+
color = class_colors[id - 1]
|
49 |
+
color_hex = "#{:02x}{:02x}{:02x}".format(*color) # Convert RGB to hex
|
50 |
+
|
51 |
+
symbol = "●" # You can choose any symbol you like
|
52 |
+
tag_info = f"{symbol} [{color_hex}] {class_name}"
|
53 |
+
extracted_tags.append(tag_info)
|
54 |
draw.text((x, y), class_name, fill='black')
|
55 |
|
56 |
+
# Joining all tags into a single string, each tag on a new line
|
57 |
+
tags_string = "\n".join(extracted_tags)
|
58 |
+
|
59 |
+
return image_mask, tags_string
|
60 |
+
|
61 |
|
62 |
|
63 |
|
|
|
85 |
demo = gr.Interface(
|
86 |
gradio_process,
|
87 |
inputs=gr.inputs.Image(type="pil"),
|
88 |
+
outputs=[gr.outputs.Image(type="pil"), gr.outputs.Textbox()],
|
89 |
title="Semantic Segmentation",
|
90 |
examples=glob.glob('./examples/*.jpg'),
|
91 |
allow_flagging="never",
|
92 |
)
|
93 |
|
|
|
|
|
94 |
demo.launch()
|