bhacquin commited on
Commit
9d3e3dd
·
verified ·
1 Parent(s): dd3858d

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +30 -104
demo.py CHANGED
@@ -159,59 +159,22 @@ def select_and_load(selected_label, experiment, message_component):
159
  try:
160
  new_experiment = generate_new_experiment()
161
 
162
- # Create new video components
163
- video_left_new = gr.Video(
164
- value=new_experiment["video_left"],
165
- label="left",
166
- elem_id="video-left",
167
- show_label=False,
168
- show_download_button=False,
169
- show_share_button=False,
170
- interactive=True,
171
- source="remote",
172
- type="filepath"
173
- )
174
- video_right_new = gr.Video(
175
- value=new_experiment["video_right"],
176
- label="right",
177
- elem_id="video-right",
178
- show_label=False,
179
- show_download_button=False,
180
- show_share_button=False,
181
- interactive=True,
182
- source="remote",
183
- type="filepath"
184
- )
185
  except Exception as e:
186
  # If generating a new experiment fails, notify the user
187
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
188
  print(f"Error generating new experiment: {e}")
189
  # Keep the current experiment and videos
190
- video_left_new = gr.Video(
191
- value=experiment["video_left"],
192
- label="left",
193
- elem_id="video-left",
194
- show_label=False,
195
- show_download_button=False,
196
- show_share_button=False,
197
- interactive=True,
198
- source="remote",
199
- type="filepath"
200
- )
201
- video_right_new = gr.Video(
202
- value=experiment["video_right"],
203
- label="right",
204
- elem_id="video-right",
205
- show_label=False,
206
- show_download_button=False,
207
- show_share_button=False,
208
- interactive=True,
209
- source="remote",
210
- type="filepath"
211
- )
212
- new_experiment = experiment # Keep the current experiment
213
-
214
- return [new_experiment, video_left_new, video_right_new, message_component.value]
215
 
216
 
217
  def skip_experiment(mode, experiment, message_component):
@@ -220,7 +183,7 @@ def skip_experiment(mode, experiment, message_component):
220
  Saves the skip and loads the next experiment.
221
  """
222
  if mode != "skip":
223
- return [experiment, gr.Video(), gr.Video(), ""]
224
 
225
  # Set selected_video to "None" to indicate skip
226
  experiment["selected_video"] = "None"
@@ -245,60 +208,20 @@ def skip_experiment(mode, experiment, message_component):
245
  try:
246
  new_experiment = generate_new_experiment()
247
 
248
- # Create new video components
249
- video_left_new = gr.Video(
250
- value=new_experiment["video_left"],
251
- label="left",
252
- elem_id="video-left",
253
- show_label=False,
254
- show_download_button=False,
255
- show_share_button=False,
256
- interactive=True,
257
- source="remote",
258
- type="filepath"
259
- )
260
- video_right_new = gr.Video(
261
- value=new_experiment["video_right"],
262
- label="right",
263
- elem_id="video-right",
264
- show_label=False,
265
- show_download_button=False,
266
- show_share_button=False,
267
- interactive=True,
268
- source="remote",
269
- type="filepath"
270
- )
271
  except Exception as e:
272
  # If generating a new experiment fails, notify the user
273
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
274
  print(f"Error generating new experiment: {e}")
275
  # Keep the current experiment and videos
276
- video_left_new = gr.Video(
277
- value=experiment["video_left"],
278
- label="left",
279
- elem_id="video-left",
280
- show_label=False,
281
- show_download_button=False,
282
- show_share_button=False,
283
- interactive=True,
284
- source="remote",
285
- type="filepath"
286
- )
287
- video_right_new = gr.Video(
288
- value=experiment["video_right"],
289
- label="right",
290
- elem_id="video-right",
291
- show_label=False,
292
- show_download_button=False,
293
- show_share_button=False,
294
- interactive=True,
295
- source="remote",
296
- type="filepath"
297
- )
298
- new_experiment = experiment # Keep the current experiment
299
-
300
- return [new_experiment, video_left_new, video_right_new, message_component.value]
301
-
302
 
303
  ##################################################################
304
  # UI Layer
@@ -328,8 +251,14 @@ css = """
328
  background-color: #00c0ff;
329
  color: white;
330
  }
 
 
 
 
 
331
  """
332
 
 
333
  with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
334
  # Initialize the state
335
  experiment = gr.State()
@@ -338,6 +267,7 @@ with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
338
  with gr.Column(scale=3, elem_id="padded"):
339
  gr.Markdown("<div style='width: 100%'><h1 style='text-align: center;'>Choose Your Preferred Video</h1></div>")
340
  gr.Markdown("<div style='width: 100%'><h3 style='text-align: center;'>Select the video you prefer.<br/>⚠️Consider fidelity and quality⚠️</h3></div>")
 
341
  btn_skip = gr.Button("I have no preference")
342
  message_component = gr.Markdown("") # For displaying messages
343
 
@@ -350,9 +280,7 @@ with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
350
  show_label=False,
351
  show_download_button=False,
352
  show_share_button=False,
353
- interactive=True,
354
- source="remote",
355
- type="filepath"
356
  )
357
  with gr.Column(scale=1):
358
  video_right_component = gr.Video(
@@ -361,9 +289,7 @@ with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
361
  show_label=False,
362
  show_download_button=False,
363
  show_share_button=False,
364
- interactive=True,
365
- source="remote",
366
- type="filepath"
367
  )
368
 
369
  with gr.Row():
 
159
  try:
160
  new_experiment = generate_new_experiment()
161
 
162
+ # Update the video components with new video paths
163
+ # Instead of creating new Video components, use .update() to change the 'value'
164
+ # This ensures that Gradio correctly updates the existing components
165
+ return [
166
+ new_experiment,
167
+ gr.Video.update(value=new_experiment["video_left"]),
168
+ gr.Video.update(value=new_experiment["video_right"]),
169
+ message_component.value
170
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  except Exception as e:
172
  # If generating a new experiment fails, notify the user
173
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
174
  print(f"Error generating new experiment: {e}")
175
  # Keep the current experiment and videos
176
+ return [experiment, gr.Video.update(value=experiment["video_left"]),
177
+ gr.Video.update(value=experiment["video_right"]), message_component.value]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
 
180
  def skip_experiment(mode, experiment, message_component):
 
183
  Saves the skip and loads the next experiment.
184
  """
185
  if mode != "skip":
186
+ return [experiment, gr.Video.update(), gr.Video.update(), ""]
187
 
188
  # Set selected_video to "None" to indicate skip
189
  experiment["selected_video"] = "None"
 
208
  try:
209
  new_experiment = generate_new_experiment()
210
 
211
+ # Update the video components with new video paths
212
+ return [
213
+ new_experiment,
214
+ gr.Video.update(value=new_experiment["video_left"]),
215
+ gr.Video.update(value=new_experiment["video_right"]),
216
+ message_component.value
217
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  except Exception as e:
219
  # If generating a new experiment fails, notify the user
220
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
221
  print(f"Error generating new experiment: {e}")
222
  # Keep the current experiment and videos
223
+ return [experiment, gr.Video.update(value=experiment["video_left"]),
224
+ gr.Video.update(value=experiment["video_right"]), message_component.value]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
  ##################################################################
227
  # UI Layer
 
251
  background-color: #00c0ff;
252
  color: white;
253
  }
254
+ .video-container {
255
+ display: flex;
256
+ justify-content: center;
257
+ align-items: center;
258
+ }
259
  """
260
 
261
+
262
  with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
263
  # Initialize the state
264
  experiment = gr.State()
 
267
  with gr.Column(scale=3, elem_id="padded"):
268
  gr.Markdown("<div style='width: 100%'><h1 style='text-align: center;'>Choose Your Preferred Video</h1></div>")
269
  gr.Markdown("<div style='width: 100%'><h3 style='text-align: center;'>Select the video you prefer.<br/>⚠️Consider fidelity and quality⚠️</h3></div>")
270
+ # Removed the submit button as per requirement
271
  btn_skip = gr.Button("I have no preference")
272
  message_component = gr.Markdown("") # For displaying messages
273
 
 
280
  show_label=False,
281
  show_download_button=False,
282
  show_share_button=False,
283
+ interactive=True
 
 
284
  )
285
  with gr.Column(scale=1):
286
  video_right_component = gr.Video(
 
289
  show_label=False,
290
  show_download_button=False,
291
  show_share_button=False,
292
+ interactive=True
 
 
293
  )
294
 
295
  with gr.Row():