Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,15 +30,50 @@ def print_directory_contents(path):
|
|
30 |
for f in files:
|
31 |
print(f"{subindent}{f}")
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def infer(text):
|
|
|
|
|
|
|
35 |
|
36 |
# set hparams
|
37 |
output_dir = 'example_1' ### change this output directory
|
38 |
|
39 |
|
40 |
duration = 30
|
41 |
-
num_samples =
|
42 |
bs = 1
|
43 |
|
44 |
|
@@ -47,12 +82,7 @@ def infer(text):
|
|
47 |
musicgen.set_generation_params(duration=duration, extend_stride=duration//2, top_k = 250)
|
48 |
|
49 |
|
50 |
-
chords = ['C G A:min F'
|
51 |
-
'A:min F C G',
|
52 |
-
'C F G F',
|
53 |
-
'C A:min F G',
|
54 |
-
'D:min G C A:min',
|
55 |
-
]
|
56 |
|
57 |
descriptions = ["A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums."] * num_samples
|
58 |
|
@@ -78,18 +108,21 @@ def infer(text):
|
|
78 |
|
79 |
# Print the outputs directory contents
|
80 |
print_directory_contents('./output_samples')
|
81 |
-
|
|
|
|
|
82 |
|
83 |
with gr.Blocks() as demo:
|
84 |
with gr.Column():
|
85 |
gr.Markdown("#MusiConGen")
|
86 |
with gr.Row():
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
90 |
submit_btn.click(
|
91 |
fn = infer,
|
92 |
inputs = [text_in],
|
93 |
-
outputs = [
|
94 |
)
|
95 |
demo.launch()
|
|
|
30 |
for f in files:
|
31 |
print(f"{subindent}{f}")
|
32 |
|
33 |
+
def check_outputs_folder(folder_path):
|
34 |
+
# Check if the folder exists
|
35 |
+
if os.path.exists(folder_path) and os.path.isdir(folder_path):
|
36 |
+
# Delete all contents inside the folder
|
37 |
+
for filename in os.listdir(folder_path):
|
38 |
+
file_path = os.path.join(folder_path, filename)
|
39 |
+
try:
|
40 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
41 |
+
os.unlink(file_path) # Remove file or link
|
42 |
+
elif os.path.isdir(file_path):
|
43 |
+
shutil.rmtree(file_path) # Remove directory
|
44 |
+
except Exception as e:
|
45 |
+
print(f'Failed to delete {file_path}. Reason: {e}')
|
46 |
+
else:
|
47 |
+
print(f'The folder {folder_path} does not exist.')
|
48 |
+
|
49 |
+
def check_for_wav_in_outputs():
|
50 |
+
# Define the path to the outputs folder
|
51 |
+
outputs_folder = './example_1'
|
52 |
+
|
53 |
+
# Check if the outputs folder exists
|
54 |
+
if not os.path.exists(outputs_folder):
|
55 |
+
return None
|
56 |
+
|
57 |
+
# Check if there is a .mp4 file in the outputs folder
|
58 |
+
mp4_files = [f for f in os.listdir(outputs_folder) if f.endswith('.wav')]
|
59 |
+
|
60 |
+
# Return the path to the mp4 file if it exists
|
61 |
+
if mp4_files:
|
62 |
+
return os.path.join(outputs_folder, mp4_files[0])
|
63 |
+
else:
|
64 |
+
return None
|
65 |
|
66 |
def infer(text):
|
67 |
+
|
68 |
+
# check if 'outputs' dir exists and empty it if necessary
|
69 |
+
check_outputs_folder('./example_1')
|
70 |
|
71 |
# set hparams
|
72 |
output_dir = 'example_1' ### change this output directory
|
73 |
|
74 |
|
75 |
duration = 30
|
76 |
+
num_samples = 1
|
77 |
bs = 1
|
78 |
|
79 |
|
|
|
82 |
musicgen.set_generation_params(duration=duration, extend_stride=duration//2, top_k = 250)
|
83 |
|
84 |
|
85 |
+
chords = ['C G A:min F']
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
descriptions = ["A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums."] * num_samples
|
88 |
|
|
|
108 |
|
109 |
# Print the outputs directory contents
|
110 |
print_directory_contents('./output_samples')
|
111 |
+
wav_file_path = check_for_wav_in_outputs()
|
112 |
+
print(wav_file_path)
|
113 |
+
return wav_file_path
|
114 |
|
115 |
with gr.Blocks() as demo:
|
116 |
with gr.Column():
|
117 |
gr.Markdown("#MusiConGen")
|
118 |
with gr.Row():
|
119 |
+
with gr.Column():
|
120 |
+
text_in = gr.Textbox()
|
121 |
+
submit_btn = gr.Button("Submit")
|
122 |
+
wav_out = gr.Audio(label="Wav Result")
|
123 |
submit_btn.click(
|
124 |
fn = infer,
|
125 |
inputs = [text_in],
|
126 |
+
outputs = [wav_out]
|
127 |
)
|
128 |
demo.launch()
|