Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -215,6 +215,12 @@ if default_model in model_choices:
|
|
215 |
model_choices.remove(default_model)
|
216 |
model_choices.insert(0, default_model)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
# Set up dark grey theme
|
219 |
theme = gr.themes.Monochrome(
|
220 |
primary_hue="gray",
|
@@ -234,7 +240,7 @@ with gr.Blocks(theme=theme) as iface:
|
|
234 |
""")
|
235 |
|
236 |
with gr.Row():
|
237 |
-
model_dropdown = gr.Dropdown(choices=model_choices, label="Select Model", value=default_model
|
238 |
|
239 |
with gr.Row():
|
240 |
prompt = gr.Textbox(label="Prompt")
|
@@ -250,15 +256,21 @@ with gr.Blocks(theme=theme) as iface:
|
|
250 |
output_audio = gr.Audio(type="filepath")
|
251 |
|
252 |
def on_model_change(model_name):
|
253 |
-
|
|
|
|
|
|
|
254 |
|
255 |
model_dropdown.change(on_model_change, inputs=[model_dropdown])
|
256 |
generate_button.click(generate_music, inputs=[prompt, seed, cfg_scale, steps, duration], outputs=[output_status, output_audio])
|
257 |
|
258 |
-
# Load default model on startup
|
259 |
-
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
262 |
|
263 |
# Launch the interface
|
264 |
iface.launch()
|
|
|
215 |
model_choices.remove(default_model)
|
216 |
model_choices.insert(0, default_model)
|
217 |
|
218 |
+
# Handle the case where no models are found
|
219 |
+
if not model_choices:
|
220 |
+
print("No model files found in the specified directory.")
|
221 |
+
model_choices = ["No models available"]
|
222 |
+
default_model = "No models available"
|
223 |
+
|
224 |
# Set up dark grey theme
|
225 |
theme = gr.themes.Monochrome(
|
226 |
primary_hue="gray",
|
|
|
240 |
""")
|
241 |
|
242 |
with gr.Row():
|
243 |
+
model_dropdown = gr.Dropdown(choices=model_choices, label="Select Model", value=default_model)
|
244 |
|
245 |
with gr.Row():
|
246 |
prompt = gr.Textbox(label="Prompt")
|
|
|
256 |
output_audio = gr.Audio(type="filepath")
|
257 |
|
258 |
def on_model_change(model_name):
|
259 |
+
if model_name != "No models available":
|
260 |
+
load_model(model_name)
|
261 |
+
else:
|
262 |
+
print("No valid model selected.")
|
263 |
|
264 |
model_dropdown.change(on_model_change, inputs=[model_dropdown])
|
265 |
generate_button.click(generate_music, inputs=[prompt, seed, cfg_scale, steps, duration], outputs=[output_status, output_audio])
|
266 |
|
267 |
+
# Load default model on startup only if it exists
|
268 |
+
if default_model != "No models available":
|
269 |
+
default_model_path = os.path.join(MODELS_DIR, default_model)
|
270 |
+
if os.path.exists(default_model_path):
|
271 |
+
iface.load(lambda: load_model(default_model), inputs=None, outputs=None)
|
272 |
+
else:
|
273 |
+
print("No default model available to load.")
|
274 |
|
275 |
# Launch the interface
|
276 |
iface.launch()
|