Ali Mohsin commited on
Commit
7facf2a
·
1 Parent(s): 509815c

feat: Add start/stop buttons and `enable_tryon` state to control virtual try-on processing.

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -196,10 +196,13 @@ def init_processor(garment_name):
196
  frame_processor.switch_to_target_garment(0)
197
 
198
  @spaces.GPU
199
- def process_frame(image, garment_name):
200
  if image is None:
201
  return None
202
 
 
 
 
203
  global frame_processor
204
  # Check if we need to load/reload
205
  # This is a basic check. Real app needs better state management.
@@ -262,6 +265,8 @@ with gr.Blocks(title="RTV: Real-Time Virtual Try-On") as app:
262
  gr.Markdown("Train a custom garment model from a video, or try on existing ones.")
263
 
264
  with gr.Tab("Virtual Try-On"):
 
 
265
  with gr.Row():
266
  with gr.Column():
267
  garment_selector = gr.Dropdown(
@@ -271,14 +276,21 @@ with gr.Blocks(title="RTV: Real-Time Virtual Try-On") as app:
271
  interactive=True
272
  )
273
  input_webcam = gr.Image(sources=["webcam"], streaming=True, label="Live Feed", interactive=True)
 
 
 
 
274
  with gr.Column():
275
  output_display = gr.Image(label="Virtual Try-On Result")
276
 
277
- # We use a button or stream event
278
- # Streaming in Gradio: image component has .stream()
 
 
 
279
  input_webcam.stream(
280
  fn=process_frame,
281
- inputs=[input_webcam, garment_selector],
282
  outputs=output_display,
283
  show_progress=False
284
  )
 
196
  frame_processor.switch_to_target_garment(0)
197
 
198
  @spaces.GPU
199
+ def process_frame(image, garment_name, enable_tryon):
200
  if image is None:
201
  return None
202
 
203
+ if not enable_tryon:
204
+ return image
205
+
206
  global frame_processor
207
  # Check if we need to load/reload
208
  # This is a basic check. Real app needs better state management.
 
265
  gr.Markdown("Train a custom garment model from a video, or try on existing ones.")
266
 
267
  with gr.Tab("Virtual Try-On"):
268
+ tryon_enabled = gr.State(False)
269
+
270
  with gr.Row():
271
  with gr.Column():
272
  garment_selector = gr.Dropdown(
 
276
  interactive=True
277
  )
278
  input_webcam = gr.Image(sources=["webcam"], streaming=True, label="Live Feed", interactive=True)
279
+ with gr.Row():
280
+ start_btn = gr.Button("Start Try-On", variant="primary")
281
+ stop_btn = gr.Button("Stop Try-On", variant="stop")
282
+
283
  with gr.Column():
284
  output_display = gr.Image(label="Virtual Try-On Result")
285
 
286
+ # Button handlers to toggle state
287
+ start_btn.click(fn=lambda: True, inputs=None, outputs=[tryon_enabled])
288
+ stop_btn.click(fn=lambda: False, inputs=None, outputs=[tryon_enabled])
289
+
290
+ # Stream now listens to the state
291
  input_webcam.stream(
292
  fn=process_frame,
293
+ inputs=[input_webcam, garment_selector, tryon_enabled],
294
  outputs=output_display,
295
  show_progress=False
296
  )