Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -279,9 +279,21 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
|
|
279 |
return f"{name}.mp4", haslyrics
|
280 |
|
281 |
def gradio_interface(audio_file, lyrics, output_name, fps=30, vidwidth=1280, vidheight=720, oscres=512, img=None, tit=None, ast=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
resolution = f"{vidwidth}x{vidheight}"
|
283 |
res = tuple(map(int, resolution.split('x')))
|
284 |
-
video_file, haslyrics = main(
|
|
|
|
|
|
|
|
|
285 |
time.sleep(5)
|
286 |
|
287 |
shutil.rmtree("out")
|
@@ -319,8 +331,11 @@ with gr.Blocks() as demo:
|
|
319 |
output_video = gr.Video(label="Output")
|
320 |
srt_output = gr.File(label="SRT Output", visible=False)
|
321 |
|
322 |
-
#
|
323 |
-
|
|
|
|
|
|
|
324 |
fn=gradio_interface,
|
325 |
inputs=[audio_file, lyrics_file, output_name, fps_slider, vidwidth_slider, vidheight_slider, oscres_slider, cover_img, title_input, artist_input],
|
326 |
outputs=[output_video, srt_output]
|
|
|
279 |
return f"{name}.mp4", haslyrics
|
280 |
|
281 |
def gradio_interface(audio_file, lyrics, output_name, fps=30, vidwidth=1280, vidheight=720, oscres=512, img=None, tit=None, ast=None):
|
282 |
+
if audio_file is None:
|
283 |
+
raise ValueError("No audio file provided.")
|
284 |
+
|
285 |
+
# Save the uploaded file to a temporary location
|
286 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio_file:
|
287 |
+
temp_audio_file.write(audio_file.read())
|
288 |
+
temp_audio_file_path = temp_audio_file.name
|
289 |
+
|
290 |
resolution = f"{vidwidth}x{vidheight}"
|
291 |
res = tuple(map(int, resolution.split('x')))
|
292 |
+
video_file, haslyrics = main(temp_audio_file_path, output_name, fps=fps, res=res, oscres=oscres, lyrics=lyrics, img=img, tit=tit, ast=ast)
|
293 |
+
|
294 |
+
# Clean up the temporary file
|
295 |
+
os.remove(temp_audio_file_path)
|
296 |
+
|
297 |
time.sleep(5)
|
298 |
|
299 |
shutil.rmtree("out")
|
|
|
331 |
output_video = gr.Video(label="Output")
|
332 |
srt_output = gr.File(label="SRT Output", visible=False)
|
333 |
|
334 |
+
# Add a submit button and link it to the gradio_interface function
|
335 |
+
submit_btn = gr.Button("Generate Video")
|
336 |
+
|
337 |
+
# Bind the button to the function
|
338 |
+
submit_btn.click(
|
339 |
fn=gradio_interface,
|
340 |
inputs=[audio_file, lyrics_file, output_name, fps_slider, vidwidth_slider, vidheight_slider, oscres_slider, cover_img, title_input, artist_input],
|
341 |
outputs=[output_video, srt_output]
|