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
...@@ -2880,9 +2880,6 @@ def print_model_list(args): ...@@ -2880,9 +2880,6 @@ def print_model_list(args):
# Check if JSON output is requested # Check if JSON output is requested
json_output = getattr(args, 'json', False) json_output = getattr(args, 'json', False)
if not json_output:
print("\nAvailable models (filtered):\n")
shown = 0 shown = 0
results = [] results = []
json_results = [] json_results = []
...@@ -2949,6 +2946,14 @@ def print_model_list(args): ...@@ -2949,6 +2946,14 @@ def print_model_list(args):
"base_model": info.get("base_model"), "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: if shown == 0:
print("No models match the selected filters.") print("No models match the selected filters.")
else: else:
...@@ -2999,11 +3004,6 @@ def print_model_list(args): ...@@ -2999,11 +3004,6 @@ def print_model_list(args):
print(f" {disabled_count} model(s) disabled for --auto mode") print(f" {disabled_count} model(s) disabled for --auto mode")
print(f" Use --model <name> manually to re-enable a disabled model") 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("\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(" --nsfw-friendly, --low-vram, --high-vram, --huge-vram")
print("\nUse --model <name> to select a model.") print("\nUse --model <name> to select a model.")
......
...@@ -123,10 +123,24 @@ def get_model_list() -> List[Dict]: ...@@ -123,10 +123,24 @@ def get_model_list() -> List[Dict]:
['python3', 'videogen', '--model-list', '--json'], ['python3', 'videogen', '--model-list', '--json'],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=30 timeout=60
) )
if result.returncode == 0: 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: except Exception as e:
print(f"Error getting model list: {e}") print(f"Error getting model list: {e}")
return [] 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