Fix JSON output for model list - output JSON before any other text

- Move JSON output to happen before table printing
- Add better error handling in webapp.py for debugging
- This fixes the web interface model list not showing
parent 53b999cb
......@@ -2879,9 +2879,6 @@ def show_model_details(model_id_or_name, args):
def print_model_list(args):
# Check if JSON output is requested
json_output = getattr(args, 'json', False)
if not json_output:
print("\nAvailable models (filtered):\n")
shown = 0
results = []
......@@ -2949,6 +2946,14 @@ def print_model_list(args):
"base_model": info.get("base_model"),
})
# JSON output - print and exit early (before any other output)
if json_output:
print(json.dumps(json_results, indent=2))
sys.exit(0)
# Print header only for non-JSON output
print("\nAvailable models (filtered):\n")
if shown == 0:
print("No models match the selected filters.")
else:
......@@ -2999,11 +3004,6 @@ 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.")
......
......@@ -123,10 +123,24 @@ def get_model_list() -> List[Dict]:
['python3', 'videogen', '--model-list', '--json'],
capture_output=True,
text=True,
timeout=30
timeout=60
)
if result.returncode == 0:
return json.loads(result.stdout)
# Try to parse JSON from stdout
stdout = result.stdout.strip()
if stdout:
try:
return json.loads(stdout)
except json.JSONDecodeError as je:
print(f"JSON parse error: {je}")
print(f"stdout (first 500 chars): {stdout[:500]}")
print(f"stderr (first 500 chars): {result.stderr[:500]}")
else:
print(f"Empty stdout from videogen --model-list --json")
print(f"stderr: {result.stderr[:500]}")
else:
print(f"videogen --model-list --json failed with return code {result.returncode}")
print(f"stderr: {result.stderr[:500]}")
except Exception as e:
print(f"Error getting model list: {e}")
return []
......
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