""" ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Script Name : debug_tabs.py Placement : HuggingFace Space — root/debug_tabs.py Type of Script : Debug Utility Purpose : Prints all gr.Tab registrations found in Space files. Run this to diagnose duplicate tab issues. Safe to delete after debugging. Version : 1.0 Usage : python3 debug_tabs.py Last Updated : 2026-03-10 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: """ import os import ast import sys #============================================================================== # SCAN ALL .py FILES FOR gr.Tab() CALLS #============================================================================== SPACE_ROOT = os.path.dirname(os.path.abspath(__file__)) print("\n" + "="*70) print(" SPIRAL CITY — TAB REGISTRATION DEBUG") print("="*70) py_files = [f for f in os.listdir(SPACE_ROOT) if f.endswith(".py")] print(f"\nšŸ“ Found {len(py_files)} Python files: {py_files}\n") tab_registry = [] for fname in sorted(py_files): fpath = os.path.join(SPACE_ROOT, fname) try: with open(fpath, "r", encoding="utf-8") as f: source = f.read() tree = ast.parse(source) found_tabs = [] for node in ast.walk(tree): # Look for gr.Tab("...") calls if isinstance(node, ast.Call): func = node.func # gr.Tab(...) if (isinstance(func, ast.Attribute) and func.attr == "Tab" and isinstance(func.value, ast.Name) and func.value.id == "gr"): if node.args: first_arg = node.args[0] if isinstance(first_arg, ast.Constant): tab_name = first_arg.value found_tabs.append((node.lineno, tab_name)) if found_tabs: print(f"šŸ“„ {fname}:") for lineno, tab_name in found_tabs: print(f" Line {lineno:4d} → gr.Tab(\"{tab_name}\")") tab_registry.append((fname, lineno, tab_name)) print() else: print(f"šŸ“„ {fname}: no gr.Tab() calls\n") except Exception as e: print(f"āŒ {fname}: parse error — {e}\n") #============================================================================== # SUMMARY — LOOK FOR DUPLICATES #============================================================================== print("="*70) print(" SUMMARY") print("="*70) from collections import Counter tab_names = [t[2] for t in tab_registry] counts = Counter(tab_names) duplicates_found = False for tab_name, count in counts.items(): if count > 1: print(f"\nāš ļø DUPLICATE: \"{tab_name}\" appears {count} times!") for fname, lineno, name in tab_registry: if name == tab_name: print(f" → {fname} line {lineno}") duplicates_found = True if not duplicates_found: print("\nāœ… No duplicate tabs found!") print(f"\nšŸ“Š Total gr.Tab() calls across all files: {len(tab_registry)}") print("\nFull tab list in registration order:") for i, (fname, lineno, tab_name) in enumerate(tab_registry, 1): print(f" {i:2d}. \"{tab_name}\" — {fname}:{lineno}") print("\n" + "="*70) print(" Also checking for demo.launch() calls (causes duplicate apps)") print("="*70 + "\n") for fname in sorted(py_files): fpath = os.path.join(SPACE_ROOT, fname) try: with open(fpath, "r", encoding="utf-8") as f: lines = f.readlines() for i, line in enumerate(lines, 1): if "demo.launch()" in line or ".launch()" in line: print(f"šŸš€ {fname} line {i}: {line.strip()}") except Exception as e: print(f"āŒ {fname}: {e}") print("\nāœ… Debug complete.\n")