ziqiangao commited on
Commit
9335655
·
1 Parent(s): 375a04d

update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -280,7 +280,7 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
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
  resolution = f"{vidwidth}x{vidheight}"
286
  res = tuple(map(int, resolution.split('x')))
@@ -288,58 +288,60 @@ def gradio_interface(audio_file, lyrics, output_name, fps=30, vidwidth=1280, vid
288
 
289
  # Clean up the temporary file
290
  os.remove(audio_file)
291
-
292
- time.sleep(5)
293
-
294
  shutil.rmtree("out")
 
295
  srt_output = "out.srt" if haslyrics else None
296
- return video_file, srt_output
297
 
298
- def update_srt_output_visibility(lyrics):
299
- haslyrics = lyrics is not None
300
  return gr.update(visible=haslyrics)
301
 
302
  with gr.Blocks() as demo:
303
  gr.Markdown('Upload an MP3 file and configure parameters to create a visualization video.\nOptionally upload a word or line synced lyric file\nEnsure a blank line at the end to avoid conversion errors')
304
-
305
- with gr.Accordion(label="Audio Settings", open=True):
306
- gr.Markdown('# Load your mp3 and lyrics file here')
307
- audio_file = gr.File(label="Upload your MP3 file", file_count='single', file_types=['mp3'])
308
- lyrics_file = gr.File(label="(Optional) Upload Lyrics as LRC or SRT", file_count='single', file_types=['lrc', 'srt'])
309
-
310
- with gr.Accordion(label="Video Output Settings"):
311
- gr.Markdown('# Configure Video Output Here')
312
- output_name = gr.Textbox(label="Output Video Name", value='video')
313
- fps_slider = gr.Slider(label="Frames per Second", minimum=20, maximum=60, step=1, value=30)
314
- vidwidth_slider = gr.Slider(label="Output Video Width", minimum=100, maximum=2000, value=1280, step=2)
315
- vidheight_slider = gr.Slider(label="Output Video Height", minimum=100, maximum=2000, value=720, step=2)
316
-
317
- with gr.Accordion(label="Advanced Options"):
318
- oscres_slider = gr.Slider(label="Number of Visualization Segments", minimum=256, maximum=2048, step=2, value=512)
319
-
320
- with gr.Accordion(label="Mp3 Metadata"):
321
- gr.Markdown('# Add Metadata here if your mp3 does not have one')
322
- cover_img = gr.Image(label='Cover Art')
323
- title_input = gr.Textbox(label='Title')
324
- artist_input = gr.Textbox(label='Artists')
325
 
326
- output_video = gr.Video(label="Output")
327
- srt_output = gr.File(label="SRT Output", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
- # Add a submit button and link it to the gradio_interface function
330
- submit_btn = gr.Button("Generate Video")
 
 
331
 
332
  # Bind the button to the function
333
  submit_btn.click(
334
  fn=gradio_interface,
335
  inputs=[audio_file, lyrics_file, output_name, fps_slider, vidwidth_slider, vidheight_slider, oscres_slider, cover_img, title_input, artist_input],
336
- outputs=[output_video, srt_output]
337
  )
338
 
339
  # Update visibility of SRT output
340
  demo.load(
341
  fn=update_srt_output_visibility,
342
- inputs=lyrics_file,
343
  outputs=srt_output
344
  )
345
 
 
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 gr.Error("Please Provide an Audio File")
284
 
285
  resolution = f"{vidwidth}x{vidheight}"
286
  res = tuple(map(int, resolution.split('x')))
 
288
 
289
  # Clean up the temporary file
290
  os.remove(audio_file)
 
 
 
291
  shutil.rmtree("out")
292
+
293
  srt_output = "out.srt" if haslyrics else None
294
+ return video_file, srt_output, haslyrics
295
 
296
+ def update_srt_output_visibility(haslyrics):
 
297
  return gr.update(visible=haslyrics)
298
 
299
  with gr.Blocks() as demo:
300
  gr.Markdown('Upload an MP3 file and configure parameters to create a visualization video.\nOptionally upload a word or line synced lyric file\nEnsure a blank line at the end to avoid conversion errors')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
 
302
+ with gr.Row():
303
+ # Inputs on the left
304
+ with gr.Column():
305
+ with gr.Accordion(label="Audio Settings", open=True):
306
+ gr.Markdown('# Load your mp3 and lyrics file here')
307
+ audio_file = gr.File(label="Upload your MP3 file", file_count='single', file_types=['mp3'])
308
+ lyrics_file = gr.File(label="(Optional) Upload Lyrics as LRC or SRT", file_count='single', file_types=['lrc', 'srt'])
309
+
310
+ with gr.Accordion(label="Video Output Settings", open=False):
311
+ gr.Markdown('# Configure Video Output Here')
312
+ output_name = gr.Textbox(label="Output Video Name", value='video')
313
+ fps_slider = gr.Slider(label="Frames per Second", minimum=20, maximum=60, step=1, value=30)
314
+ vidwidth_slider = gr.Slider(label="Output Video Width", minimum=100, maximum=2000, value=1280, step=2)
315
+ vidheight_slider = gr.Slider(label="Output Video Height", minimum=100, maximum=2000, value=720, step=2)
316
+
317
+ with gr.Accordion(label="Advanced Options", open=False):
318
+ oscres_slider = gr.Slider(label="Number of Visualization Segments", minimum=256, maximum=2048, step=2, value=512)
319
+
320
+ with gr.Accordion(label="Mp3 Metadata", open=False):
321
+ gr.Markdown('# Add Metadata here if your mp3 does not have one')
322
+ cover_img = gr.Image(label='Cover Art')
323
+ title_input = gr.Textbox(label='Title')
324
+ artist_input = gr.Textbox(label='Artists')
325
+
326
+ # Add a submit button
327
+ submit_btn = gr.Button("Generate Video")
328
 
329
+ # Outputs on the right
330
+ with gr.Column():
331
+ output_video = gr.Video(label="Output")
332
+ srt_output = gr.File(label="SRT Output", visible=False)
333
 
334
  # Bind the button to the function
335
  submit_btn.click(
336
  fn=gradio_interface,
337
  inputs=[audio_file, lyrics_file, output_name, fps_slider, vidwidth_slider, vidheight_slider, oscres_slider, cover_img, title_input, artist_input],
338
+ outputs=[output_video, srt_output, gr.State()]
339
  )
340
 
341
  # Update visibility of SRT output
342
  demo.load(
343
  fn=update_srt_output_visibility,
344
+ inputs=gr.State(),
345
  outputs=srt_output
346
  )
347