quarterbitgames commited on
Commit
ca6344d
Β·
verified Β·
1 Parent(s): 56b708b

Create debug_tabs.py

Browse files
Files changed (1) hide show
  1. debug_tabs.py +114 -0
debug_tabs.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3
+ Script Name : debug_tabs.py
4
+ Placement : HuggingFace Space β€” root/debug_tabs.py
5
+ Type of Script : Debug Utility
6
+ Purpose : Prints all gr.Tab registrations found in Space files.
7
+ Run this to diagnose duplicate tab issues.
8
+ Safe to delete after debugging.
9
+ Version : 1.0
10
+ Usage : python3 debug_tabs.py
11
+ Last Updated : 2026-03-10
12
+ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
13
+ """
14
+
15
+ import os
16
+ import ast
17
+ import sys
18
+
19
+ #==============================================================================
20
+ # SCAN ALL .py FILES FOR gr.Tab() CALLS
21
+ #==============================================================================
22
+
23
+ SPACE_ROOT = os.path.dirname(os.path.abspath(__file__))
24
+
25
+ print("\n" + "="*70)
26
+ print(" SPIRAL CITY β€” TAB REGISTRATION DEBUG")
27
+ print("="*70)
28
+
29
+ py_files = [f for f in os.listdir(SPACE_ROOT) if f.endswith(".py")]
30
+ print(f"\nπŸ“ Found {len(py_files)} Python files: {py_files}\n")
31
+
32
+ tab_registry = []
33
+
34
+ for fname in sorted(py_files):
35
+ fpath = os.path.join(SPACE_ROOT, fname)
36
+ try:
37
+ with open(fpath, "r", encoding="utf-8") as f:
38
+ source = f.read()
39
+
40
+ tree = ast.parse(source)
41
+ found_tabs = []
42
+
43
+ for node in ast.walk(tree):
44
+ # Look for gr.Tab("...") calls
45
+ if isinstance(node, ast.Call):
46
+ func = node.func
47
+ # gr.Tab(...)
48
+ if (isinstance(func, ast.Attribute) and
49
+ func.attr == "Tab" and
50
+ isinstance(func.value, ast.Name) and
51
+ func.value.id == "gr"):
52
+ if node.args:
53
+ first_arg = node.args[0]
54
+ if isinstance(first_arg, ast.Constant):
55
+ tab_name = first_arg.value
56
+ found_tabs.append((node.lineno, tab_name))
57
+
58
+ if found_tabs:
59
+ print(f"πŸ“„ {fname}:")
60
+ for lineno, tab_name in found_tabs:
61
+ print(f" Line {lineno:4d} β†’ gr.Tab(\"{tab_name}\")")
62
+ tab_registry.append((fname, lineno, tab_name))
63
+ print()
64
+ else:
65
+ print(f"πŸ“„ {fname}: no gr.Tab() calls\n")
66
+
67
+ except Exception as e:
68
+ print(f"❌ {fname}: parse error β€” {e}\n")
69
+
70
+ #==============================================================================
71
+ # SUMMARY β€” LOOK FOR DUPLICATES
72
+ #==============================================================================
73
+
74
+ print("="*70)
75
+ print(" SUMMARY")
76
+ print("="*70)
77
+
78
+ from collections import Counter
79
+ tab_names = [t[2] for t in tab_registry]
80
+ counts = Counter(tab_names)
81
+
82
+ duplicates_found = False
83
+ for tab_name, count in counts.items():
84
+ if count > 1:
85
+ print(f"\n⚠️ DUPLICATE: \"{tab_name}\" appears {count} times!")
86
+ for fname, lineno, name in tab_registry:
87
+ if name == tab_name:
88
+ print(f" β†’ {fname} line {lineno}")
89
+ duplicates_found = True
90
+
91
+ if not duplicates_found:
92
+ print("\nβœ… No duplicate tabs found!")
93
+
94
+ print(f"\nπŸ“Š Total gr.Tab() calls across all files: {len(tab_registry)}")
95
+ print("\nFull tab list in registration order:")
96
+ for i, (fname, lineno, tab_name) in enumerate(tab_registry, 1):
97
+ print(f" {i:2d}. \"{tab_name}\" β€” {fname}:{lineno}")
98
+
99
+ print("\n" + "="*70)
100
+ print(" Also checking for demo.launch() calls (causes duplicate apps)")
101
+ print("="*70 + "\n")
102
+
103
+ for fname in sorted(py_files):
104
+ fpath = os.path.join(SPACE_ROOT, fname)
105
+ try:
106
+ with open(fpath, "r", encoding="utf-8") as f:
107
+ lines = f.readlines()
108
+ for i, line in enumerate(lines, 1):
109
+ if "demo.launch()" in line or ".launch()" in line:
110
+ print(f"πŸš€ {fname} line {i}: {line.strip()}")
111
+ except Exception as e:
112
+ print(f"❌ {fname}: {e}")
113
+
114
+ print("\nβœ… Debug complete.\n")