Antoni Bigata commited on
Commit
e67de88
·
1 Parent(s): a5ed597

requirements

Browse files
Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -617,7 +617,7 @@ def sample(
617
  return complete_video
618
 
619
 
620
- @spaces.GPU(duration=200)
621
  @torch.no_grad()
622
  def process_video(video_input, audio_input, max_num_seconds):
623
  """Main processing function to generate synchronized video"""
@@ -945,29 +945,29 @@ def process_video(video_input, audio_input, max_num_seconds):
945
  # return None
946
 
947
 
948
- def get_max_duration(video_input, audio_input):
949
- """Get the maximum duration in seconds for the slider"""
950
- try:
951
- # Default to 60 seconds if files don't exist
952
- if video_input is None or not os.path.exists(video_input):
953
- video_input = DEFAULT_VIDEO_PATH
954
 
955
- if audio_input is None or not os.path.exists(audio_input):
956
- audio_input = DEFAULT_AUDIO_PATH
957
 
958
- # Get video duration
959
- video_reader = decord.VideoReader(video_input)
960
- video_duration = len(video_reader) / video_reader.get_avg_fps()
961
 
962
- # Get audio duration
963
- raw_audio = get_raw_audio(audio_input, 16000)
964
- audio_duration = len(raw_audio) / 25 # Assuming 25 fps
965
 
966
- # Return the minimum of the two durations
967
- return min(video_duration, audio_duration)
968
- except Exception as e:
969
- print(f"Error getting max duration: {str(e)}")
970
- return 60 # Default to 60 seconds
971
 
972
 
973
  def new_game_click(state):
@@ -1015,38 +1015,38 @@ with gr.Blocks(
1015
  else None,
1016
  )
1017
 
1018
- max_duration = gr.State(value=60) # Default max duration
1019
 
1020
- max_seconds_slider = gr.Slider(
1021
- minimum=0,
1022
- maximum=60, # Will be updated dynamically
1023
- value=0,
1024
- step=1,
1025
- label="Max Duration (seconds, 0 = full length)",
1026
- info="Limit the processing duration (0 means use full length)",
1027
- )
1028
 
1029
  process_button = gr.Button("Generate Synchronized Video")
1030
 
1031
  with gr.Column("Output Video"):
1032
  video_output = gr.Video(label="Output Video", width=512, height=512)
1033
 
1034
- # Update slider max value when inputs change
1035
- def update_slider_max(video, audio):
1036
- max_dur = get_max_duration(video, audio)
1037
- return {"maximum": max_dur, "__type__": "update"}
1038
 
1039
- video_input.change(
1040
- update_slider_max, [video_input, audio_input], [max_seconds_slider]
1041
- )
1042
- audio_input.change(
1043
- update_slider_max, [video_input, audio_input], [max_seconds_slider]
1044
- )
1045
 
1046
  # Show Wordle message when processing starts and hide when complete
1047
  process_button.click(
1048
  fn=process_video,
1049
- inputs=[video_input, audio_input, max_seconds_slider],
1050
  outputs=video_output,
1051
  )
1052
 
 
617
  return complete_video
618
 
619
 
620
+ @spaces.GPU(duration=150)
621
  @torch.no_grad()
622
  def process_video(video_input, audio_input, max_num_seconds):
623
  """Main processing function to generate synchronized video"""
 
945
  # return None
946
 
947
 
948
+ # def get_max_duration(video_input, audio_input):
949
+ # """Get the maximum duration in seconds for the slider"""
950
+ # try:
951
+ # # Default to 60 seconds if files don't exist
952
+ # if video_input is None or not os.path.exists(video_input):
953
+ # video_input = DEFAULT_VIDEO_PATH
954
 
955
+ # if audio_input is None or not os.path.exists(audio_input):
956
+ # audio_input = DEFAULT_AUDIO_PATH
957
 
958
+ # # Get video duration
959
+ # video_reader = decord.VideoReader(video_input)
960
+ # video_duration = len(video_reader) / video_reader.get_avg_fps()
961
 
962
+ # # Get audio duration
963
+ # raw_audio = get_raw_audio(audio_input, 16000)
964
+ # audio_duration = len(raw_audio) / 25 # Assuming 25 fps
965
 
966
+ # # Return the minimum of the two durations
967
+ # return min(video_duration, audio_duration)
968
+ # except Exception as e:
969
+ # print(f"Error getting max duration: {str(e)}")
970
+ # return 60 # Default to 60 seconds
971
 
972
 
973
  def new_game_click(state):
 
1015
  else None,
1016
  )
1017
 
1018
+ # max_duration = gr.State(value=60) # Default max duration
1019
 
1020
+ # max_seconds_slider = gr.Slider(
1021
+ # minimum=0,
1022
+ # maximum=60, # Will be updated dynamically
1023
+ # value=0,
1024
+ # step=1,
1025
+ # label="Max Duration (seconds, 0 = full length)",
1026
+ # info="Limit the processing duration (0 means use full length)",
1027
+ # )
1028
 
1029
  process_button = gr.Button("Generate Synchronized Video")
1030
 
1031
  with gr.Column("Output Video"):
1032
  video_output = gr.Video(label="Output Video", width=512, height=512)
1033
 
1034
+ # # Update slider max value when inputs change
1035
+ # def update_slider_max(video, audio):
1036
+ # max_dur = get_max_duration(video, audio)
1037
+ # return {"maximum": max_dur, "__type__": "update"}
1038
 
1039
+ # video_input.change(
1040
+ # update_slider_max, [video_input, audio_input], [max_seconds_slider]
1041
+ # )
1042
+ # audio_input.change(
1043
+ # update_slider_max, [video_input, audio_input], [max_seconds_slider]
1044
+ # )
1045
 
1046
  # Show Wordle message when processing starts and hide when complete
1047
  process_button.click(
1048
  fn=process_video,
1049
+ inputs=[video_input, audio_input, 10],
1050
  outputs=video_output,
1051
  )
1052