fffiloni commited on
Commit
d097c66
·
verified ·
1 Parent(s): afe8ed6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -187,9 +187,9 @@ def process_final_combination(audio_in, chosen_translated, volume, cut_start, vi
187
  temp_output_path = overlay_audio(audio_in, chosen_translated, volume, cut_start)
188
 
189
  if video_input:
190
- return gr.update(value=temp_output_path, visible=True), gr.update(visible=True)
191
  else:
192
- return gr.update(value=temp_output_path, visible=True), gr.update(visible=False)
193
 
194
  def replace_video_audio(video_path: str, new_audio_path: str) -> str:
195
  """Replaces the original audio in the video and extends it if the new audio is longer.
@@ -234,9 +234,12 @@ def replace_video_audio(video_path: str, new_audio_path: str) -> str:
234
 
235
 
236
  return gr.update(value=temp_video.name, visible=True) # Return path to temp video file
 
 
 
237
 
238
  def hide_previous():
239
- return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
240
 
241
  css="""
242
  div#col-container{
@@ -263,8 +266,8 @@ with gr.Blocks(css=css) as demo:
263
  )
264
  choose_this_btn = gr.Button("Use this one", scale=1, visible=False)
265
  with gr.Row():
266
- volume_reduction = gr.Slider(label="Volume reduction", minimum=0, maximum=60, step=1, value=30)
267
- cut_start = gr.Slider(label="Cut start", minimum=0.0, maximum=4.0, step=0.1, value=2.0)
268
  combined_output = gr.Audio("Combined Output", type="filepath", visible=False)
269
  apply_to_video_btn = gr.Button("Apply to video", visible=False)
270
  final_video_out = gr.Video(label="Video + Translated Audio", visible=False)
@@ -280,6 +283,12 @@ with gr.Blocks(css=css) as demo:
280
  inputs = [audio_input]
281
  )
282
 
 
 
 
 
 
 
283
  video_input.upload(
284
  fn = extract_audio_as_mp3,
285
  inputs = [video_input],
@@ -296,7 +305,7 @@ with gr.Blocks(css=css) as demo:
296
  choose_this_btn.click(
297
  fn = process_final_combination,
298
  inputs = [audio_input, dropdown_wav_selector, volume_reduction, cut_start, video_input],
299
- outputs = [combined_output, apply_to_video_btn]
300
  )
301
 
302
  apply_to_video_btn.click(
@@ -308,7 +317,7 @@ with gr.Blocks(css=css) as demo:
308
  submit_btn.click(
309
  fn = hide_previous,
310
  inputs = None,
311
- outputs = [dropdown_wav_selector, result_accordion, wav_list, choose_this_btn, combined_output, apply_to_video_btn, final_video_out]
312
  ).then(
313
  fn = infer,
314
  inputs = [audio_input],
 
187
  temp_output_path = overlay_audio(audio_in, chosen_translated, volume, cut_start)
188
 
189
  if video_input:
190
+ return gr.update(value=temp_output_path, visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
191
  else:
192
+ return gr.update(value=temp_output_path, visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
193
 
194
  def replace_video_audio(video_path: str, new_audio_path: str) -> str:
195
  """Replaces the original audio in the video and extends it if the new audio is longer.
 
234
 
235
 
236
  return gr.update(value=temp_video.name, visible=True) # Return path to temp video file
237
+
238
+ def clean_previous_video_input():
239
+ return gr.update(value=None)
240
 
241
  def hide_previous():
242
+ return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
243
 
244
  css="""
245
  div#col-container{
 
266
  )
267
  choose_this_btn = gr.Button("Use this one", scale=1, visible=False)
268
  with gr.Row():
269
+ volume_reduction = gr.Slider(label="Volume reduction", minimum=0, maximum=60, step=1, value=30, visible=False)
270
+ cut_start = gr.Slider(label="Cut start", minimum=0.0, maximum=4.0, step=0.1, value=2.0, visible=False)
271
  combined_output = gr.Audio("Combined Output", type="filepath", visible=False)
272
  apply_to_video_btn = gr.Button("Apply to video", visible=False)
273
  final_video_out = gr.Video(label="Video + Translated Audio", visible=False)
 
283
  inputs = [audio_input]
284
  )
285
 
286
+ audio_input.upload(
287
+ fn = clean_previous_video_input,
288
+ inputs = None,
289
+ outputs = [video_input]
290
+ )
291
+
292
  video_input.upload(
293
  fn = extract_audio_as_mp3,
294
  inputs = [video_input],
 
305
  choose_this_btn.click(
306
  fn = process_final_combination,
307
  inputs = [audio_input, dropdown_wav_selector, volume_reduction, cut_start, video_input],
308
+ outputs = [combined_output, apply_to_video_btn, volume_reduction, cut_start]
309
  )
310
 
311
  apply_to_video_btn.click(
 
317
  submit_btn.click(
318
  fn = hide_previous,
319
  inputs = None,
320
+ outputs = [dropdown_wav_selector, result_accordion, wav_list, choose_this_btn, combined_output, apply_to_video_btn, final_video_out, volume_reduction, cut_start]
321
  ).then(
322
  fn = infer,
323
  inputs = [audio_input],