Add --json flag for model list output (for web interface)

- Add --json argument to output model list in JSON format
- Include model capabilities, disabled status, and fail count in JSON output
- This fixes the web interface model list not showing models
parent 4e2361f9
......@@ -2866,10 +2866,15 @@ def show_model_details(model_id_or_name, args):
def print_model_list(args):
print("\nAvailable models (filtered):\n")
# Check if JSON output is requested
json_output = getattr(args, 'json', False)
if not json_output:
print("\nAvailable models (filtered):\n")
shown = 0
results = []
json_results = []
# Load auto-disable data for showing disabled status
auto_disable_data = load_auto_disable_data()
......@@ -2917,6 +2922,21 @@ def print_model_list(args):
fail_count = get_model_fail_count(model_id, name)
results.append((name, info, caps, is_disabled, fail_count))
# Build JSON result
if json_output:
json_results.append({
"name": name,
"id": info.get("id", ""),
"vram": info.get("vram", ""),
"class": info.get("class", ""),
"desc": info.get("desc", ""),
"capabilities": caps,
"is_disabled": is_disabled,
"fail_count": fail_count,
"is_lora": info.get("is_lora", False),
"base_model": info.get("base_model"),
})
if shown == 0:
print("No models match the selected filters.")
......@@ -2968,6 +2988,11 @@ def print_model_list(args):
print(f" {disabled_count} model(s) disabled for --auto mode")
print(f" Use --model <name> manually to re-enable a disabled model")
# JSON output
if json_output:
print(json.dumps(json_results, indent=2))
sys.exit(0)
print("\nFilters: --t2v-only, --i2v-only, --t2i-only, --v2v-only, --v2i-only, --3d-only, --tts-only, --audio-only")
print(" --nsfw-friendly, --low-vram, --high-vram, --huge-vram")
print("\nUse --model <name> to select a model.")
......@@ -8890,6 +8915,8 @@ List TTS voices:
# Model listing arguments
parser.add_argument("--model-list", action="store_true",
help="Print list of all available models and exit")
parser.add_argument("--json", action="store_true",
help="Output model list in JSON format (for web interface)")
parser.add_argument("--tts-list", action="store_true",
help="Print list of all available TTS voices and exit")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment