Disable buttons when no API key set
Browse files
app.py
CHANGED
|
@@ -22,10 +22,10 @@ def create_demo():
|
|
| 22 |
gr.Markdown(f"**Import Error:** {IMPORT_ERROR}")
|
| 23 |
return demo
|
| 24 |
|
| 25 |
-
with gr.Accordion("Settings", open=
|
| 26 |
api_key = gr.Textbox(
|
| 27 |
label="StackNet Key",
|
| 28 |
-
placeholder="Enter your key
|
| 29 |
type="password",
|
| 30 |
value=""
|
| 31 |
)
|
|
@@ -33,6 +33,33 @@ def create_demo():
|
|
| 33 |
with gr.Tabs():
|
| 34 |
tabs = create_all_tabs()
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Text to Music
|
| 37 |
ttm = tabs["text_to_music"]
|
| 38 |
ttm["generate_btn"].click(
|
|
|
|
| 22 |
gr.Markdown(f"**Import Error:** {IMPORT_ERROR}")
|
| 23 |
return demo
|
| 24 |
|
| 25 |
+
with gr.Accordion("Settings", open=True):
|
| 26 |
api_key = gr.Textbox(
|
| 27 |
label="StackNet Key",
|
| 28 |
+
placeholder="Enter your key to enable generation...",
|
| 29 |
type="password",
|
| 30 |
value=""
|
| 31 |
)
|
|
|
|
| 33 |
with gr.Tabs():
|
| 34 |
tabs = create_all_tabs()
|
| 35 |
|
| 36 |
+
# Collect all buttons to disable when no API key
|
| 37 |
+
all_buttons = [
|
| 38 |
+
tabs["text_to_music"]["generate_btn"],
|
| 39 |
+
tabs["music_to_music"]["cover_btn"],
|
| 40 |
+
tabs["music_to_music"]["stems_btn"],
|
| 41 |
+
tabs["text_to_image"]["generate_btn"],
|
| 42 |
+
tabs["image_to_image"]["edit_btn"],
|
| 43 |
+
tabs["text_to_video"]["generate_btn"],
|
| 44 |
+
tabs["image_to_video"]["animate_btn"],
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
def update_buttons(key):
|
| 48 |
+
enabled = bool(key and key.strip())
|
| 49 |
+
return [gr.update(interactive=enabled) for _ in all_buttons]
|
| 50 |
+
|
| 51 |
+
api_key.change(
|
| 52 |
+
fn=update_buttons,
|
| 53 |
+
inputs=[api_key],
|
| 54 |
+
outputs=all_buttons
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Initially disable all buttons
|
| 58 |
+
demo.load(
|
| 59 |
+
fn=lambda: [gr.update(interactive=False) for _ in all_buttons],
|
| 60 |
+
outputs=all_buttons
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
# Text to Music
|
| 64 |
ttm = tabs["text_to_music"]
|
| 65 |
ttm["generate_btn"].click(
|