bhacquin commited on
Commit
2940ad4
·
verified ·
1 Parent(s): dabc6db

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +34 -8
demo.py CHANGED
@@ -126,6 +126,23 @@ def generate_new_experiment() -> Experiment:
126
  )
127
 
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  def select_and_load(selected_label, experiment, message_component):
130
  """
131
  Handles the selection of a video by the user.
@@ -160,8 +177,6 @@ def select_and_load(selected_label, experiment, message_component):
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"]),
@@ -173,8 +188,12 @@ def select_and_load(selected_label, experiment, message_component):
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):
@@ -220,8 +239,12 @@ def skip_experiment(mode, experiment, message_component):
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
@@ -256,9 +279,12 @@ css = """
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()
@@ -327,7 +353,7 @@ with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
327
 
328
  # Load the first experiment on app startup
329
  demo.load(
330
- fn=generate_new_experiment,
331
  inputs=None,
332
  outputs=[experiment, video_left_component, video_right_component, message_component]
333
  )
 
126
  )
127
 
128
 
129
+ def load_initial():
130
+ """
131
+ Initializes the first experiment on app load.
132
+ """
133
+ try:
134
+ new_experiment = generate_new_experiment()
135
+ return [
136
+ new_experiment,
137
+ gr.Video.update(value=new_experiment["video_left"]),
138
+ gr.Video.update(value=new_experiment["video_right"]),
139
+ "" # Empty message
140
+ ]
141
+ except Exception as e:
142
+ print(f"Error loading initial experiment: {e}")
143
+ return [None, gr.Video.update(value=""), gr.Video.update(value=""), "❌ Failed to load initial videos ❌"]
144
+
145
+
146
  def select_and_load(selected_label, experiment, message_component):
147
  """
148
  Handles the selection of a video by the user.
 
177
  new_experiment = generate_new_experiment()
178
 
179
  # Update the video components with new video paths
 
 
180
  return [
181
  new_experiment,
182
  gr.Video.update(value=new_experiment["video_left"]),
 
188
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
189
  print(f"Error generating new experiment: {e}")
190
  # Keep the current experiment and videos
191
+ return [
192
+ experiment,
193
+ gr.Video.update(value=experiment["video_left"]),
194
+ gr.Video.update(value=experiment["video_right"]),
195
+ message_component.value
196
+ ]
197
 
198
 
199
  def skip_experiment(mode, experiment, message_component):
 
239
  message_component.value = f"❌ Failed to load new videos: {e} ❌"
240
  print(f"Error generating new experiment: {e}")
241
  # Keep the current experiment and videos
242
+ return [
243
+ experiment,
244
+ gr.Video.update(value=experiment["video_left"]),
245
+ gr.Video.update(value=experiment["video_right"]),
246
+ message_component.value
247
+ ]
248
 
249
  ##################################################################
250
  # UI Layer
 
279
  justify-content: center;
280
  align-items: center;
281
  }
282
+ video {
283
+ width: 100%;
284
+ height: auto;
285
+ }
286
  """
287
 
 
288
  with gr.Blocks(title="Unsupervised Video Editing", css=css) as demo:
289
  # Initialize the state
290
  experiment = gr.State()
 
353
 
354
  # Load the first experiment on app startup
355
  demo.load(
356
+ fn=load_initial,
357
  inputs=None,
358
  outputs=[experiment, video_left_component, video_right_component, message_component]
359
  )