Spaces:
Running
on
A10G
Running
on
A10G
BertChristiaens
commited on
Commit
•
9bfe550
1
Parent(s):
0d84e52
transparant background
Browse files
app.py
CHANGED
@@ -100,15 +100,18 @@ def make_prompt_row():
|
|
100 |
def make_sidebar():
|
101 |
with st.sidebar:
|
102 |
input_image = st.file_uploader("", type=["png", "jpg"], key='input_image', on_change=on_upload)
|
103 |
-
generation_mode = st.selectbox("Generation mode", ["
|
|
|
|
|
104 |
|
105 |
-
paint_mode = st.sidebar.selectbox("Painting mode", ("freedraw", "polygon"))
|
106 |
-
if paint_mode == "freedraw":
|
107 |
-
brush = st.slider("Stroke width", 5, 140, 100, key='slider_seg')
|
108 |
-
else:
|
109 |
-
brush = 5
|
110 |
|
111 |
if generation_mode == "Segmentation conditioning":
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
category_chooser = st.sidebar.selectbox("Filter on category", list(
|
113 |
COLOR_MAPPING_CATEGORY.keys()), index=0, key='category_chooser')
|
114 |
|
@@ -117,7 +120,19 @@ def make_sidebar():
|
|
117 |
color_chooser = st.sidebar.selectbox(
|
118 |
"Choose a color", chosen_colors, index=0, format_func=map_colors, key='color_chooser'
|
119 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
color_chooser = "#000000"
|
122 |
return input_image, generation_mode, brush, color_chooser, paint_mode
|
123 |
|
@@ -147,7 +162,7 @@ def make_editing_canvas(canvas_color, brush, _reset_state, generation_mode, pain
|
|
147 |
_reset_state=_reset_state
|
148 |
)
|
149 |
|
150 |
-
if generation_mode == "
|
151 |
canvas = st_canvas(
|
152 |
**canvas_dict,
|
153 |
)
|
@@ -168,9 +183,8 @@ def make_editing_canvas(canvas_color, brush, _reset_state, generation_mode, pain
|
|
168 |
options=st.session_state['unique_colors'],
|
169 |
key='chosen_colors',
|
170 |
default=st.session_state['unique_colors'],
|
171 |
-
format_func=map_colors_rgb
|
172 |
)
|
173 |
-
print(st.session_state['unique_colors'])
|
174 |
|
175 |
if st.button("generate image", key='generate_button'):
|
176 |
image = get_image()
|
@@ -181,7 +195,6 @@ def make_editing_canvas(canvas_color, brush, _reset_state, generation_mode, pain
|
|
181 |
for color in chosen_colors:
|
182 |
# if the color is in the segmentation, set mask to 1
|
183 |
mask[np.where((segmentation == color).all(axis=2))] = 1
|
184 |
-
print(mask)
|
185 |
|
186 |
with st.spinner(text="Generating image"):
|
187 |
result_image = make_image_controlnet(image=image,
|
|
|
100 |
def make_sidebar():
|
101 |
with st.sidebar:
|
102 |
input_image = st.file_uploader("", type=["png", "jpg"], key='input_image', on_change=on_upload)
|
103 |
+
generation_mode = st.selectbox("Generation mode", ["Re-generate objects",
|
104 |
+
"Segmentation conditioning",
|
105 |
+
"Inpainting"], on_change=on_change_radio)
|
106 |
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
if generation_mode == "Segmentation conditioning":
|
109 |
+
paint_mode = st.sidebar.selectbox("Painting mode", ("freedraw", "polygon"))
|
110 |
+
if paint_mode == "freedraw":
|
111 |
+
brush = st.slider("Stroke width", 5, 140, 100, key='slider_seg')
|
112 |
+
else:
|
113 |
+
brush = 5
|
114 |
+
|
115 |
category_chooser = st.sidebar.selectbox("Filter on category", list(
|
116 |
COLOR_MAPPING_CATEGORY.keys()), index=0, key='category_chooser')
|
117 |
|
|
|
120 |
color_chooser = st.sidebar.selectbox(
|
121 |
"Choose a color", chosen_colors, index=0, format_func=map_colors, key='color_chooser'
|
122 |
)
|
123 |
+
|
124 |
+
elif generation_mode == "Re-generate objects":
|
125 |
+
color_chooser = "rgba(0, 0, 0, 0.0)"
|
126 |
+
paint_mode = 'freedraw'
|
127 |
+
brush = 0
|
128 |
+
|
129 |
else:
|
130 |
+
paint_mode = st.sidebar.selectbox("Painting mode", ("freedraw", "polygon"))
|
131 |
+
if paint_mode == "freedraw":
|
132 |
+
brush = st.slider("Stroke width", 5, 140, 100, key='slider_seg')
|
133 |
+
else:
|
134 |
+
brush = 5
|
135 |
+
|
136 |
color_chooser = "#000000"
|
137 |
return input_image, generation_mode, brush, color_chooser, paint_mode
|
138 |
|
|
|
162 |
_reset_state=_reset_state
|
163 |
)
|
164 |
|
165 |
+
if generation_mode == "Re-generate objects":
|
166 |
canvas = st_canvas(
|
167 |
**canvas_dict,
|
168 |
)
|
|
|
183 |
options=st.session_state['unique_colors'],
|
184 |
key='chosen_colors',
|
185 |
default=st.session_state['unique_colors'],
|
186 |
+
format_func=map_colors_rgb,
|
187 |
)
|
|
|
188 |
|
189 |
if st.button("generate image", key='generate_button'):
|
190 |
image = get_image()
|
|
|
195 |
for color in chosen_colors:
|
196 |
# if the color is in the segmentation, set mask to 1
|
197 |
mask[np.where((segmentation == color).all(axis=2))] = 1
|
|
|
198 |
|
199 |
with st.spinner(text="Generating image"):
|
200 |
result_image = make_image_controlnet(image=image,
|