Update app.py
Browse files
app.py
CHANGED
@@ -164,32 +164,57 @@ def gradio_interface():
|
|
164 |
if initial_image_pil is not None:
|
165 |
image_history = [initial_image_pil]
|
166 |
current_image_pil = initial_image_pil
|
167 |
-
return current_image_pil, image_history, initial_image_pil, {}, gr.
|
168 |
else:
|
169 |
-
return None, [], None, {}, gr.
|
170 |
|
171 |
# When the initial image is uploaded, initialize the image history
|
172 |
-
initial_image.upload(
|
|
|
|
|
|
|
|
|
173 |
|
174 |
# Segment button click
|
175 |
def segment_image_wrapper(current_image_pil, prompts):
|
176 |
if current_image_pil is None:
|
177 |
-
return "No image uploaded.", {}, gr.
|
178 |
masks = extract_masks(current_image_pil, prompts)
|
179 |
if not masks:
|
180 |
-
return "No masks detected for the given prompts.", {}, gr.
|
181 |
dropdown_choices = list(masks.keys())
|
182 |
-
return "Segmentation completed.", masks, gr.
|
183 |
|
184 |
-
segment_button.click(
|
|
|
|
|
|
|
|
|
185 |
|
186 |
# Apply button click
|
187 |
-
apply_button.click(
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# Undo button click
|
192 |
-
undo_button.click(
|
|
|
|
|
|
|
|
|
193 |
|
194 |
demo.launch(share=True)
|
195 |
|
|
|
164 |
if initial_image_pil is not None:
|
165 |
image_history = [initial_image_pil]
|
166 |
current_image_pil = initial_image_pil
|
167 |
+
return current_image_pil, image_history, initial_image_pil, {}, gr.update(choices=[], value=None), "Image loaded."
|
168 |
else:
|
169 |
+
return None, [], None, {}, gr.update(choices=[], value=None), "No image loaded."
|
170 |
|
171 |
# When the initial image is uploaded, initialize the image history
|
172 |
+
initial_image.upload(
|
173 |
+
fn=initialize_image,
|
174 |
+
inputs=initial_image,
|
175 |
+
outputs=[current_image_pil, image_history, current_image_display, masks_dict, segment_dropdown, status]
|
176 |
+
)
|
177 |
|
178 |
# Segment button click
|
179 |
def segment_image_wrapper(current_image_pil, prompts):
|
180 |
if current_image_pil is None:
|
181 |
+
return "No image uploaded.", {}, gr.update(choices=[], value=None)
|
182 |
masks = extract_masks(current_image_pil, prompts)
|
183 |
if not masks:
|
184 |
+
return "No masks detected for the given prompts.", {}, gr.update(choices=[], value=None)
|
185 |
dropdown_choices = list(masks.keys())
|
186 |
+
return "Segmentation completed.", masks, gr.update(choices=dropdown_choices, value=dropdown_choices[0])
|
187 |
|
188 |
+
segment_button.click(
|
189 |
+
fn=segment_image_wrapper,
|
190 |
+
inputs=[current_image_pil, prompts],
|
191 |
+
outputs=[status, masks_dict, segment_dropdown]
|
192 |
+
)
|
193 |
|
194 |
# Apply button click
|
195 |
+
apply_button.click(
|
196 |
+
fn=process_image,
|
197 |
+
inputs=[
|
198 |
+
current_image_pil,
|
199 |
+
segment_dropdown,
|
200 |
+
masks_dict,
|
201 |
+
replacement_image,
|
202 |
+
color_ref_image,
|
203 |
+
apply_replacement,
|
204 |
+
apply_color_grading,
|
205 |
+
apply_color_to_full_image,
|
206 |
+
blending_amount,
|
207 |
+
image_history
|
208 |
+
],
|
209 |
+
outputs=[current_image_pil, status, image_history, current_image_display]
|
210 |
+
)
|
211 |
|
212 |
# Undo button click
|
213 |
+
undo_button.click(
|
214 |
+
fn=undo,
|
215 |
+
inputs=image_history,
|
216 |
+
outputs=[current_image_pil, image_history, current_image_display]
|
217 |
+
)
|
218 |
|
219 |
demo.launch(share=True)
|
220 |
|