Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import json
|
|
| 13 |
from typing import Optional, Dict, List, Any
|
| 14 |
import uvicorn
|
| 15 |
import traceback
|
|
|
|
| 16 |
|
| 17 |
# ============================================================================
|
| 18 |
# 2. SHARED GLOBALS & CONFIGURATION
|
|
@@ -559,8 +560,13 @@ def get_schema_info_ui():
|
|
| 559 |
"""
|
| 560 |
md = f"# π Database Schema\n\n"
|
| 561 |
md += f"**Repo:** [{INDEXED_REPO_ID}](https://huggingface.co/datasets/{INDEXED_REPO_ID})\n"
|
| 562 |
-
md += f"**Database File:** `{DB_PATH}`\n\n"
|
| 563 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
try:
|
| 565 |
with get_db_connection() as conn:
|
| 566 |
cursor = conn.cursor()
|
|
@@ -667,7 +673,7 @@ def create_gradio_ui():
|
|
| 667 |
raw_status = gr.Markdown()
|
| 668 |
raw_results = gr.DataFrame(label="SQL Results", interactive=False)
|
| 669 |
|
| 670 |
-
with gr.TabItem("π Schema"):
|
| 671 |
gr.Markdown("View the database schema and table counts.")
|
| 672 |
schema_btn = gr.Button("π Load Schema Info")
|
| 673 |
schema_output = gr.Markdown()
|
|
@@ -711,12 +717,13 @@ def create_gradio_ui():
|
|
| 711 |
outputs=[raw_results, raw_status]
|
| 712 |
)
|
| 713 |
|
| 714 |
-
# Use .
|
| 715 |
-
|
| 716 |
fn=get_schema_info_ui,
|
| 717 |
inputs=None,
|
| 718 |
outputs=[schema_output]
|
| 719 |
)
|
|
|
|
| 720 |
schema_btn.click(
|
| 721 |
fn=get_schema_info_ui,
|
| 722 |
inputs=None,
|
|
|
|
| 13 |
from typing import Optional, Dict, List, Any
|
| 14 |
import uvicorn
|
| 15 |
import traceback
|
| 16 |
+
from pathlib import Path # <-- FIX 1: Added this import
|
| 17 |
|
| 18 |
# ============================================================================
|
| 19 |
# 2. SHARED GLOBALS & CONFIGURATION
|
|
|
|
| 560 |
"""
|
| 561 |
md = f"# π Database Schema\n\n"
|
| 562 |
md += f"**Repo:** [{INDEXED_REPO_ID}](https://huggingface.co/datasets/{INDEXED_REPO_ID})\n"
|
|
|
|
| 563 |
|
| 564 |
+
if DB_PATH:
|
| 565 |
+
md += f"**Database File:** `{DB_PATH}`\n\n"
|
| 566 |
+
else:
|
| 567 |
+
md += "**Database File:** `NOT LOADED`\n\n"
|
| 568 |
+
return md
|
| 569 |
+
|
| 570 |
try:
|
| 571 |
with get_db_connection() as conn:
|
| 572 |
cursor = conn.cursor()
|
|
|
|
| 673 |
raw_status = gr.Markdown()
|
| 674 |
raw_results = gr.DataFrame(label="SQL Results", interactive=False)
|
| 675 |
|
| 676 |
+
with gr.TabItem("π Schema") as schema_tab: # <-- FIX 2: Added variable 'schema_tab'
|
| 677 |
gr.Markdown("View the database schema and table counts.")
|
| 678 |
schema_btn = gr.Button("π Load Schema Info")
|
| 679 |
schema_output = gr.Markdown()
|
|
|
|
| 717 |
outputs=[raw_results, raw_status]
|
| 718 |
)
|
| 719 |
|
| 720 |
+
# --- FIX 2: Use schema_tab.select() to load data when the tab is clicked ---
|
| 721 |
+
schema_tab.select(
|
| 722 |
fn=get_schema_info_ui,
|
| 723 |
inputs=None,
|
| 724 |
outputs=[schema_output]
|
| 725 |
)
|
| 726 |
+
# We can also keep the button for a manual refresh
|
| 727 |
schema_btn.click(
|
| 728 |
fn=get_schema_info_ui,
|
| 729 |
inputs=None,
|