Spaces:
Sleeping
Sleeping
fix
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ colors = [
|
|
59 |
]
|
60 |
|
61 |
color_map = {
|
62 |
-
color_id: f"#{hex(color[2])[2:].zfill(2)}{hex(color[1])[2:].zfill(2)}{hex(color[0])[2:].zfill(2)}" for color_id, color in enumerate(colors)
|
63 |
}
|
64 |
|
65 |
def run_clip_dinoiser(input_image, text_prompts):
|
@@ -80,21 +80,6 @@ def run_clip_dinoiser(input_image, text_prompts):
|
|
80 |
output = output[0].argmax(dim=0)
|
81 |
mask = mask2rgb(output, palette)
|
82 |
|
83 |
-
# fig = plt.figure(figsize=(3, 1))
|
84 |
-
# classes = np.unique(output).tolist()
|
85 |
-
# plt.imshow(np.array(itemgetter(*classes)(palette)).reshape(1, -1, 3))
|
86 |
-
# plt.xticks(np.arange(len(classes)), list(itemgetter(*classes)(text_prompts)), rotation=45)
|
87 |
-
# plt.yticks([])
|
88 |
-
|
89 |
-
|
90 |
-
# fig, ax = plt.subplots(nrows=1, ncols=2)
|
91 |
-
# alpha=0.5
|
92 |
-
# blend = (alpha)*np.array(image)/255. + (1-alpha) * mask/255.
|
93 |
-
# ax[0].imshow(blend)
|
94 |
-
# ax[1].imshow(mask)
|
95 |
-
# ax[0].axis('off')
|
96 |
-
# ax[1].axis('off')
|
97 |
-
|
98 |
classes = np.unique(output).tolist()
|
99 |
palette_array = np.array(itemgetter(*classes)(palette)).reshape(1, -1, 3)
|
100 |
alpha=0.5
|
@@ -102,7 +87,7 @@ def run_clip_dinoiser(input_image, text_prompts):
|
|
102 |
|
103 |
h_text = list()
|
104 |
for idx, text in enumerate(text_prompts):
|
105 |
-
h_text.append((text, idx))
|
106 |
return blend, mask, h_text
|
107 |
|
108 |
|
@@ -116,7 +101,7 @@ if __name__ == "__main__":
|
|
116 |
|
117 |
with gr.Row():
|
118 |
with gr.Column():
|
119 |
-
input_image = gr.Image(type="pil")
|
120 |
text_prompts = gr.Textbox(label="Enter comma-separated prompts")
|
121 |
run_button = gr.Button(value="Run")
|
122 |
|
@@ -124,12 +109,14 @@ if __name__ == "__main__":
|
|
124 |
with gr.Row():
|
125 |
overlay_mask = gr.Image(
|
126 |
type="numpy",
|
|
|
127 |
)
|
128 |
only_mask = gr.Image(
|
129 |
type="numpy",
|
|
|
130 |
)
|
131 |
h_text = gr.HighlightedText(
|
132 |
-
label="
|
133 |
combine_adjacent=False,
|
134 |
show_legend=False,
|
135 |
color_map=color_map
|
|
|
59 |
]
|
60 |
|
61 |
color_map = {
|
62 |
+
f"{color_id}": f"#{hex(color[2])[2:].zfill(2)}{hex(color[1])[2:].zfill(2)}{hex(color[0])[2:].zfill(2)}" for color_id, color in enumerate(colors)
|
63 |
}
|
64 |
|
65 |
def run_clip_dinoiser(input_image, text_prompts):
|
|
|
80 |
output = output[0].argmax(dim=0)
|
81 |
mask = mask2rgb(output, palette)
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
classes = np.unique(output).tolist()
|
84 |
palette_array = np.array(itemgetter(*classes)(palette)).reshape(1, -1, 3)
|
85 |
alpha=0.5
|
|
|
87 |
|
88 |
h_text = list()
|
89 |
for idx, text in enumerate(text_prompts):
|
90 |
+
h_text.append((text, f"{idx}"))
|
91 |
return blend, mask, h_text
|
92 |
|
93 |
|
|
|
101 |
|
102 |
with gr.Row():
|
103 |
with gr.Column():
|
104 |
+
input_image = gr.Image(type="pil", label="Input Image")
|
105 |
text_prompts = gr.Textbox(label="Enter comma-separated prompts")
|
106 |
run_button = gr.Button(value="Run")
|
107 |
|
|
|
109 |
with gr.Row():
|
110 |
overlay_mask = gr.Image(
|
111 |
type="numpy",
|
112 |
+
label="Overlay Mask",
|
113 |
)
|
114 |
only_mask = gr.Image(
|
115 |
type="numpy",
|
116 |
+
label="Segmentation Mask"
|
117 |
)
|
118 |
h_text = gr.HighlightedText(
|
119 |
+
label="Labels",
|
120 |
combine_adjacent=False,
|
121 |
show_legend=False,
|
122 |
color_map=color_map
|