fffiloni commited on
Commit
97a8787
·
1 Parent(s): c11930b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -74,11 +74,26 @@ def infer(video_input, manual_caption, duration_in, seed, caption_output):
74
  # AudioLDM loaded demo returns a video, so we only keep the audio
75
  video = VideoFileClip(sound)
76
  audio = video.audio
77
- audio.write_audiofile("sound.mp3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  #return cap, sound[1], gr.Textbox.update(placeholder=f"{ph_update}{ph_message}"), gr.Group.update(visible=True)
80
  #return cap, "sound.mp3", gr.Group.update(visible=True)
81
- return cap, "sound.mp3"
82
 
83
  title = """
84
  <div style="text-align: center; max-width: 700px; margin: 0 auto;">
@@ -139,13 +154,13 @@ with gr.Blocks(css="style.css") as demo:
139
  input_vid = gr.Video(source="upload", type="filepath", elem_id="input-vid")
140
 
141
  with gr.Column():
142
- manual_cap = gr.Textbox(label="Manual Image description (optional)", lines=3, placeholder=ph_message)
143
  with gr.Row():
144
  duration_in = gr.Slider(interactive=False, minimum=5, maximum=10, step=5, value=5, label="Duration")
145
  seed_in = gr.Slider(label="Seed", value=440, minimum=45, maximum=10000, step=1)
146
 
147
  caption_output = gr.Textbox(label="Caption", visible=False, elem_id="text-caption")
148
- sound_output = gr.Audio(label="Result", elem_id="sound-output")
149
  #debug = gr.Textbox()
150
  generate = gr.Button("Generate SFX from Video")
151
 
@@ -156,12 +171,12 @@ with gr.Blocks(css="style.css") as demo:
156
 
157
  gr.HTML(article)
158
 
159
- change_out = [manual_cap, caption_output, sound_output]
160
  input_vid.change(input_changes, input_vid, change_out, queue=False)
161
 
162
 
163
 
164
- generate.click(infer, inputs=[input_vid, manual_cap, duration_in, seed_in, caption_output], outputs=[caption_output, sound_output], api_name="v2fx")
165
  #share_button.click(None, [], [], _js=share_js)
166
 
167
  demo.queue(max_size=32).launch(debug=True)
 
74
  # AudioLDM loaded demo returns a video, so we only keep the audio
75
  video = VideoFileClip(sound)
76
  audio = video.audio
77
+ #audio.write_audiofile("sound.mp3")
78
+
79
+ # Then we put the audio to the original video
80
+
81
+ # Load the input video file
82
+ video_in = VideoFileClip(video_input)
83
+
84
+ # Make the audio the same length as the video
85
+ audio = audio.set_duration(video.duration)
86
+
87
+ # Combine the audio and video
88
+ result = video_in.set_audio(audio)
89
+
90
+ # Save the result
91
+ result.write_videofile("result.mp4")
92
+
93
 
94
  #return cap, sound[1], gr.Textbox.update(placeholder=f"{ph_update}{ph_message}"), gr.Group.update(visible=True)
95
  #return cap, "sound.mp3", gr.Group.update(visible=True)
96
+ return cap, "result.mp4"
97
 
98
  title = """
99
  <div style="text-align: center; max-width: 700px; margin: 0 auto;">
 
154
  input_vid = gr.Video(source="upload", type="filepath", elem_id="input-vid")
155
 
156
  with gr.Column():
157
+ manual_cap = gr.Textbox(label="Manual Video description (optional)", lines=3, placeholder=ph_message)
158
  with gr.Row():
159
  duration_in = gr.Slider(interactive=False, minimum=5, maximum=10, step=5, value=5, label="Duration")
160
  seed_in = gr.Slider(label="Seed", value=440, minimum=45, maximum=10000, step=1)
161
 
162
  caption_output = gr.Textbox(label="Caption", visible=False, elem_id="text-caption")
163
+ video_output = gr.Video(label="Result", elem_id="video-output")
164
  #debug = gr.Textbox()
165
  generate = gr.Button("Generate SFX from Video")
166
 
 
171
 
172
  gr.HTML(article)
173
 
174
+ change_out = [manual_cap, caption_output, video_output]
175
  input_vid.change(input_changes, input_vid, change_out, queue=False)
176
 
177
 
178
 
179
+ generate.click(infer, inputs=[input_vid, manual_cap, duration_in, seed_in, caption_output], outputs=[caption_output, video_output], api_name="v2fx")
180
  #share_button.click(None, [], [], _js=share_js)
181
 
182
  demo.queue(max_size=32).launch(debug=True)