Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,25 +151,6 @@ def apply_mask(person_img, mask_index, seed, randomize_seed):
|
|
| 151 |
print(f"Error applying mask: {e}")
|
| 152 |
return person_img, seed, f"Error: {e}"
|
| 153 |
|
| 154 |
-
def capture_and_process(mask_index, seed, randomize_seed):
|
| 155 |
-
"""Capture from webcam and apply selected mask"""
|
| 156 |
-
if mask_index is None or mask_index >= len(MASK_IMAGES):
|
| 157 |
-
return None, None, "Invalid mask selection"
|
| 158 |
-
|
| 159 |
-
mask_img = MASK_IMAGES[mask_index]
|
| 160 |
-
if mask_img is None:
|
| 161 |
-
return None, None, "Mask not found"
|
| 162 |
-
|
| 163 |
-
cap = cv2.VideoCapture(0)
|
| 164 |
-
ret, frame = cap.read()
|
| 165 |
-
cap.release()
|
| 166 |
-
|
| 167 |
-
if not ret:
|
| 168 |
-
return None, seed, "Failed to capture image"
|
| 169 |
-
|
| 170 |
-
pil_image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 171 |
-
return apply_mask(pil_image, mask_index, seed, randomize_seed)
|
| 172 |
-
|
| 173 |
# Create interface
|
| 174 |
with gr.Blocks(css=css) as MaskSuggest:
|
| 175 |
gr.Markdown("# Mask Suggestion App")
|
|
@@ -232,17 +213,5 @@ with gr.Blocks(css=css) as MaskSuggest:
|
|
| 232 |
outputs=[image_out, seed_used, result_info],
|
| 233 |
api_name='apply_mask'
|
| 234 |
)
|
| 235 |
-
|
| 236 |
-
gr.Markdown("### Webcam Version")
|
| 237 |
-
with gr.Row():
|
| 238 |
-
webcam_button = gr.Button("Capture from Webcam")
|
| 239 |
-
webcam_output = gr.Image(label="Webcam Result")
|
| 240 |
-
webcam_status = gr.Textbox(label="Webcam Status")
|
| 241 |
-
|
| 242 |
-
webcam_button.click(
|
| 243 |
-
fn=capture_and_process,
|
| 244 |
-
inputs=[mask_selection, seed, randomize_seed],
|
| 245 |
-
outputs=[webcam_output, seed_used, webcam_status]
|
| 246 |
-
)
|
| 247 |
|
| 248 |
MaskSuggest.queue(api_open=False).launch(show_api=False)
|
|
|
|
| 151 |
print(f"Error applying mask: {e}")
|
| 152 |
return person_img, seed, f"Error: {e}"
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
# Create interface
|
| 155 |
with gr.Blocks(css=css) as MaskSuggest:
|
| 156 |
gr.Markdown("# Mask Suggestion App")
|
|
|
|
| 213 |
outputs=[image_out, seed_used, result_info],
|
| 214 |
api_name='apply_mask'
|
| 215 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
MaskSuggest.queue(api_open=False).launch(show_api=False)
|