Spaces:
Running
Running
ziqiangao
commited on
Commit
·
93e5d9e
1
Parent(s):
061964a
refactor ui
Browse files
app.py
CHANGED
@@ -17,6 +17,8 @@ import time
|
|
17 |
import shutil
|
18 |
import LRC2SRT
|
19 |
|
|
|
|
|
20 |
path = "" # Update with your path
|
21 |
|
22 |
def safe_read(i: int, a: list):
|
@@ -198,6 +200,9 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
|
|
198 |
global iii
|
199 |
iii = 0
|
200 |
# Load the audio file
|
|
|
|
|
|
|
201 |
p(0.25, "loading file")
|
202 |
audio_path = file
|
203 |
y, sr = librosa.load(audio_path, sr=sr) # Resample to 11025 Hz
|
@@ -213,9 +218,9 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
|
|
213 |
if img:
|
214 |
cover_img = cover_file
|
215 |
else:
|
216 |
-
raise gr.Error("Mp3 must have a cover image, upload the image under the 'Metadata' section", duration="
|
217 |
elif cover_img == -1 and not (tit or ast):
|
218 |
-
raise gr.Error("Mp3 is missing tags, add the info under the 'Metadata' section", duration="
|
219 |
|
220 |
title, artist = getTitleAndArtist(audio_path)
|
221 |
if title == '' or artist == '':
|
@@ -297,7 +302,7 @@ 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
|
301 |
|
302 |
with gr.Row():
|
303 |
# Inputs on the left
|
@@ -305,17 +310,18 @@ with gr.Blocks() as demo:
|
|
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 |
-
|
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='
|
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')
|
|
|
17 |
import shutil
|
18 |
import LRC2SRT
|
19 |
|
20 |
+
flag = 1
|
21 |
+
|
22 |
path = "" # Update with your path
|
23 |
|
24 |
def safe_read(i: int, a: list):
|
|
|
200 |
global iii
|
201 |
iii = 0
|
202 |
# Load the audio file
|
203 |
+
if flag:
|
204 |
+
gr.Info("This is the first file since startup, this may take some time")
|
205 |
+
flag = 0
|
206 |
p(0.25, "loading file")
|
207 |
audio_path = file
|
208 |
y, sr = librosa.load(audio_path, sr=sr) # Resample to 11025 Hz
|
|
|
218 |
if img:
|
219 |
cover_img = cover_file
|
220 |
else:
|
221 |
+
raise gr.Error("Mp3 must have a cover image, upload the image under the 'Metadata' section", duration="100")
|
222 |
elif cover_img == -1 and not (tit or ast):
|
223 |
+
raise gr.Error("Mp3 is missing tags, add the info under the 'Metadata' section", duration="100")
|
224 |
|
225 |
title, artist = getTitleAndArtist(audio_path)
|
226 |
if title == '' or artist == '':
|
|
|
302 |
return gr.update(visible=haslyrics)
|
303 |
|
304 |
with gr.Blocks() as demo:
|
305 |
+
gr.Markdown(('Upload an MP3 file and configure parameters to create a visualization video.','Optionally upload a word or line synced lyric file in the advanced section.','Ensure a blank line at the end to avoid conversion errors'))
|
306 |
|
307 |
with gr.Row():
|
308 |
# Inputs on the left
|
|
|
310 |
with gr.Accordion(label="Audio Settings", open=True):
|
311 |
gr.Markdown('# Load your mp3 and lyrics file here')
|
312 |
audio_file = gr.File(label="Upload your MP3 file", file_count='single', file_types=['mp3'])
|
313 |
+
|
314 |
|
315 |
with gr.Accordion(label="Video Output Settings", open=False):
|
316 |
gr.Markdown('# Configure Video Output Here')
|
317 |
+
output_name = gr.Textbox(label="Output Video Name", value='Output')
|
318 |
fps_slider = gr.Slider(label="Frames per Second", minimum=20, maximum=60, step=1, value=30)
|
319 |
vidwidth_slider = gr.Slider(label="Output Video Width", minimum=100, maximum=2000, value=1280, step=2)
|
320 |
vidheight_slider = gr.Slider(label="Output Video Height", minimum=100, maximum=2000, value=720, step=2)
|
321 |
|
322 |
with gr.Accordion(label="Advanced Options", open=False):
|
323 |
oscres_slider = gr.Slider(label="Number of Visualization Segments", minimum=256, maximum=2048, step=2, value=512)
|
324 |
+
lyrics_file = gr.File(label="(Optional) Upload Lyrics as LRC or SRT", file_count='single', file_types=['lrc', 'srt'])
|
325 |
|
326 |
with gr.Accordion(label="Mp3 Metadata", open=False):
|
327 |
gr.Markdown('# Add Metadata here if your mp3 does not have one')
|