Spaces:
Sleeping
Sleeping
File size: 3,684 Bytes
f103ad7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | """
Settings & Health tab — API key management, health checks, and version info.
"""
import gradio as gr
from core import config, runner
from core.formatter import format_result
def create_settings_tab(session_keys):
"""Build the Settings & Health tab."""
with gr.Tab("⚙️ Settings & Health"):
gr.Markdown("## API Key Configuration\nKeys are stored in session only — never written to disk.")
key_inputs = {}
with gr.Row():
with gr.Column():
for key_name, meta in list(config.API_KEYS.items())[:4]:
key_inputs[key_name] = gr.Textbox(
label=f"{meta['label']}",
info=f"{meta['description']} — [Get key]({meta['url']})",
type="password",
value="",
placeholder="Paste key here...",
)
with gr.Column():
for key_name, meta in list(config.API_KEYS.items())[4:]:
key_inputs[key_name] = gr.Textbox(
label=f"{meta['label']}",
info=f"{meta['description']} — [Get key]({meta['url']})",
type="password",
value="",
placeholder="Paste key here...",
)
gr.Markdown("### Additional Configuration")
config_inputs = {}
for var_name, meta in config.CONFIG_VARS.items():
config_inputs[var_name] = gr.Textbox(
label=meta["label"],
info=meta["description"],
value="",
placeholder="Leave blank for default",
)
save_btn = gr.Button("💾 Save Keys to Session", variant="primary")
save_status = gr.Markdown("")
gr.Markdown("---")
gr.Markdown("## System Checks")
with gr.Row():
health_btn = gr.Button("🏥 Health Check", variant="secondary")
version_btn = gr.Button("ℹ️ Version Info", variant="secondary")
check_output_md = gr.Markdown("")
with gr.Accordion("Raw JSON", open=False):
check_output_json = gr.Code(language="json")
def save_keys(*values):
all_keys = list(config.API_KEYS.keys()) + list(config.CONFIG_VARS.keys())
keys = {}
for name, val in zip(all_keys, values):
keys[name] = val.strip() if val else ""
filled = sum(1 for v in keys.values() if v)
return keys, f"**Saved {filled} key(s) to session.** These will be used for all commands."
all_key_components = list(key_inputs.values()) + list(config_inputs.values())
save_btn.click(
fn=save_keys,
inputs=all_key_components,
outputs=[session_keys, save_status],
)
def run_health(keys):
env = config.build_env_overrides(keys)
result = runner.run_markdown(["health", "--apis-only"], env_overrides=env, timeout=30)
md, js = format_result(result)
return md, js
health_btn.click(
fn=run_health,
inputs=[session_keys],
outputs=[check_output_md, check_output_json],
)
def run_version(keys):
env = config.build_env_overrides(keys)
result = runner.run_markdown(["version"], env_overrides=env, timeout=10)
md, js = format_result(result)
return md, js
version_btn.click(
fn=run_version,
inputs=[session_keys],
outputs=[check_output_md, check_output_json],
)
|