Update app.py
Browse files
app.py
CHANGED
|
@@ -72,14 +72,6 @@ def refresh_registry_data():
|
|
| 72 |
def on_load():
|
| 73 |
return gr.Dropdown(choices=refresh_registry_data())
|
| 74 |
|
| 75 |
-
def update_version_dd(standard):
|
| 76 |
-
if not standard:
|
| 77 |
-
return gr.Dropdown(choices=[])
|
| 78 |
-
versions = sorted(set(
|
| 79 |
-
d["version"] for d in db_registry if d["standard"] == standard
|
| 80 |
-
))
|
| 81 |
-
return gr.Dropdown(choices=versions)
|
| 82 |
-
|
| 83 |
def update_category_dd(standard, version):
|
| 84 |
print("DEBUG category:", standard, version, flush=True)
|
| 85 |
|
|
@@ -91,31 +83,24 @@ def update_category_dd(standard, version):
|
|
| 91 |
try:
|
| 92 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 93 |
conn = sqlite3.connect(target["path"])
|
| 94 |
-
|
| 95 |
conn.text_factory = safe_text_factory
|
| 96 |
|
| 97 |
-
tables = pd.read_sql(
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
print("TABLES:", tables, flush=True)
|
| 100 |
|
| 101 |
main_t = f"{standard}_{version}"
|
|
|
|
| 102 |
|
| 103 |
-
print("MAIN TABLE:", main_t, flush=True) # 👈 이것도 추가
|
| 104 |
-
if not standard or not version:
|
| 105 |
-
return gr.Dropdown(choices=[])
|
| 106 |
-
|
| 107 |
-
choices = ["ALL"]
|
| 108 |
-
|
| 109 |
-
try:
|
| 110 |
-
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 111 |
-
conn = sqlite3.connect(target["path"])
|
| 112 |
-
|
| 113 |
-
conn.text_factory = safe_text_factory
|
| 114 |
-
|
| 115 |
-
tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
|
| 116 |
-
main_t = f"{standard}_{version}"
|
| 117 |
if main_t not in tables:
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
|
| 121 |
lower = [c.lower() for c in cols]
|
|
@@ -124,7 +109,10 @@ def update_category_dd(standard, version):
|
|
| 124 |
ch = cols[lower.index('chapter')]
|
| 125 |
ca = cols[lower.index('category')]
|
| 126 |
|
| 127 |
-
df = pd.read_sql(
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
for _, r in df.iterrows():
|
| 130 |
choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
|
|
|
|
| 72 |
def on_load():
|
| 73 |
return gr.Dropdown(choices=refresh_registry_data())
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
def update_category_dd(standard, version):
|
| 76 |
print("DEBUG category:", standard, version, flush=True)
|
| 77 |
|
|
|
|
| 83 |
try:
|
| 84 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 85 |
conn = sqlite3.connect(target["path"])
|
|
|
|
| 86 |
conn.text_factory = safe_text_factory
|
| 87 |
|
| 88 |
+
tables = pd.read_sql(
|
| 89 |
+
"SELECT name FROM sqlite_master WHERE type='table';",
|
| 90 |
+
conn
|
| 91 |
+
)['name'].tolist()
|
| 92 |
|
| 93 |
+
print("TABLES:", tables, flush=True)
|
| 94 |
|
| 95 |
main_t = f"{standard}_{version}"
|
| 96 |
+
print("MAIN TABLE:", main_t, flush=True)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
if main_t not in tables:
|
| 99 |
+
print("⚠️ main table not found → fallback", flush=True)
|
| 100 |
+
main_t = tables[0] if tables else None
|
| 101 |
+
|
| 102 |
+
if not main_t:
|
| 103 |
+
return gr.Dropdown(choices=[])
|
| 104 |
|
| 105 |
cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
|
| 106 |
lower = [c.lower() for c in cols]
|
|
|
|
| 109 |
ch = cols[lower.index('chapter')]
|
| 110 |
ca = cols[lower.index('category')]
|
| 111 |
|
| 112 |
+
df = pd.read_sql(
|
| 113 |
+
f"SELECT DISTINCT [{ch}], [{ca}] FROM [{main_t}]",
|
| 114 |
+
conn
|
| 115 |
+
)
|
| 116 |
|
| 117 |
for _, r in df.iterrows():
|
| 118 |
choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
|