Spaces:
Sleeping
Sleeping
sedrick-keh-tri
commited on
Commit
·
dc79d04
1
Parent(s):
c428340
vibe coded
Browse files- README.md +27 -0
- app.py +190 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -9,4 +9,31 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# VLA Foundry Database Viewer
|
| 13 |
+
|
| 14 |
+
Interactive visualization tool for exploring the VLA Foundry database from the [TRI-ML/vla_foundry_database](https://huggingface.co/datasets/TRI-ML/vla_foundry_database) dataset.
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- 📊 **Interactive Table Viewer**: Browse all tables in the database
|
| 19 |
+
- 🔍 **Search**: Search across all columns in the selected table
|
| 20 |
+
- 🎯 **Filter**: Filter by specific columns (show non-null values)
|
| 21 |
+
- 🔄 **Sort**: Sort by any column in ascending or descending order
|
| 22 |
+
- 📈 **Table Info**: View table statistics (row count, column count, column names)
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
1. Select a table from the dropdown menu
|
| 27 |
+
2. Use the search box to find specific entries
|
| 28 |
+
3. Filter by column to focus on specific data
|
| 29 |
+
4. Sort by any column to organize the data
|
| 30 |
+
5. Click "Clear Filters" to reset all filters
|
| 31 |
+
|
| 32 |
+
## Local Development
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
pip install -r requirements.txt
|
| 36 |
+
python app.py
|
| 37 |
+
```
|
| 38 |
+
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import sqlite3
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Download the database from HF dataset
|
| 8 |
+
def download_database():
|
| 9 |
+
"""Download vla_foundry.db from the HF dataset"""
|
| 10 |
+
try:
|
| 11 |
+
db_path = hf_hub_download(
|
| 12 |
+
repo_id="TRI-ML/vla_foundry_database",
|
| 13 |
+
filename="vla_foundry.db",
|
| 14 |
+
repo_type="dataset"
|
| 15 |
+
)
|
| 16 |
+
return db_path
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Error downloading database: {e}")
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
# Load data from database
|
| 22 |
+
def load_database_tables(db_path):
|
| 23 |
+
"""Load all tables from the database"""
|
| 24 |
+
if not db_path or not os.path.exists(db_path):
|
| 25 |
+
return {}, []
|
| 26 |
+
|
| 27 |
+
conn = sqlite3.connect(db_path)
|
| 28 |
+
cursor = conn.cursor()
|
| 29 |
+
|
| 30 |
+
# Get all table names
|
| 31 |
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
| 32 |
+
tables = [row[0] for row in cursor.fetchall()]
|
| 33 |
+
|
| 34 |
+
# Load each table into a DataFrame
|
| 35 |
+
table_data = {}
|
| 36 |
+
for table in tables:
|
| 37 |
+
try:
|
| 38 |
+
df = pd.read_sql_query(f"SELECT * FROM {table}", conn)
|
| 39 |
+
table_data[table] = df
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Error loading table {table}: {e}")
|
| 42 |
+
|
| 43 |
+
conn.close()
|
| 44 |
+
return table_data, tables
|
| 45 |
+
|
| 46 |
+
# Initialize database
|
| 47 |
+
db_path = download_database()
|
| 48 |
+
table_data, table_names = load_database_tables(db_path)
|
| 49 |
+
|
| 50 |
+
# Function to get table data with filters
|
| 51 |
+
def get_filtered_data(table_name, search_query="", column_filter="All", sort_column="", sort_order="Ascending"):
|
| 52 |
+
"""Get filtered and sorted data from selected table"""
|
| 53 |
+
if table_name not in table_data:
|
| 54 |
+
return pd.DataFrame()
|
| 55 |
+
|
| 56 |
+
df = table_data[table_name].copy()
|
| 57 |
+
|
| 58 |
+
# Apply search filter
|
| 59 |
+
if search_query.strip():
|
| 60 |
+
# Search across all columns
|
| 61 |
+
mask = df.astype(str).apply(lambda x: x.str.contains(search_query, case=False, na=False)).any(axis=1)
|
| 62 |
+
df = df[mask]
|
| 63 |
+
|
| 64 |
+
# Apply column-specific filter
|
| 65 |
+
if column_filter != "All" and column_filter in df.columns:
|
| 66 |
+
# Show only rows where the selected column has non-null values
|
| 67 |
+
df = df[df[column_filter].notna()]
|
| 68 |
+
|
| 69 |
+
# Apply sorting
|
| 70 |
+
if sort_column and sort_column in df.columns:
|
| 71 |
+
ascending = (sort_order == "Ascending")
|
| 72 |
+
df = df.sort_values(by=sort_column, ascending=ascending)
|
| 73 |
+
|
| 74 |
+
return df
|
| 75 |
+
|
| 76 |
+
def update_column_choices(table_name):
|
| 77 |
+
"""Update column choices based on selected table"""
|
| 78 |
+
if table_name not in table_data:
|
| 79 |
+
return gr.update(choices=["All"]), gr.update(choices=[])
|
| 80 |
+
|
| 81 |
+
columns = ["All"] + list(table_data[table_name].columns)
|
| 82 |
+
return gr.update(choices=columns, value="All"), gr.update(choices=list(table_data[table_name].columns), value="")
|
| 83 |
+
|
| 84 |
+
def get_table_info(table_name):
|
| 85 |
+
"""Get information about the selected table"""
|
| 86 |
+
if table_name not in table_data:
|
| 87 |
+
return "No table selected"
|
| 88 |
+
|
| 89 |
+
df = table_data[table_name]
|
| 90 |
+
info = f"**Table: {table_name}**\n\n"
|
| 91 |
+
info += f"- Total rows: {len(df)}\n"
|
| 92 |
+
info += f"- Total columns: {len(df.columns)}\n"
|
| 93 |
+
info += f"- Columns: {', '.join(df.columns)}\n"
|
| 94 |
+
|
| 95 |
+
return info
|
| 96 |
+
|
| 97 |
+
# Create Gradio interface
|
| 98 |
+
with gr.Blocks(title="VLA Foundry Database Viewer") as demo:
|
| 99 |
+
gr.Markdown("# 🤖 VLA Foundry Database Viewer")
|
| 100 |
+
gr.Markdown("Explore the VLA Foundry database with searchable, filterable, and sortable tables.")
|
| 101 |
+
|
| 102 |
+
if not table_data:
|
| 103 |
+
gr.Markdown("⚠️ **Error**: Could not load database. Please check if the database file exists in the dataset.")
|
| 104 |
+
else:
|
| 105 |
+
with gr.Row():
|
| 106 |
+
with gr.Column(scale=1):
|
| 107 |
+
table_selector = gr.Dropdown(
|
| 108 |
+
choices=table_names,
|
| 109 |
+
label="Select Table",
|
| 110 |
+
value=table_names[0] if table_names else None
|
| 111 |
+
)
|
| 112 |
+
table_info = gr.Markdown(
|
| 113 |
+
value=get_table_info(table_names[0]) if table_names else ""
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
gr.Markdown("### Filters")
|
| 117 |
+
search_box = gr.Textbox(
|
| 118 |
+
label="Search (across all columns)",
|
| 119 |
+
placeholder="Enter search term...",
|
| 120 |
+
value=""
|
| 121 |
+
)
|
| 122 |
+
column_filter = gr.Dropdown(
|
| 123 |
+
choices=["All"],
|
| 124 |
+
label="Filter by Column (show non-null)",
|
| 125 |
+
value="All"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
gr.Markdown("### Sorting")
|
| 129 |
+
sort_column = gr.Dropdown(
|
| 130 |
+
choices=[],
|
| 131 |
+
label="Sort by Column",
|
| 132 |
+
value=""
|
| 133 |
+
)
|
| 134 |
+
sort_order = gr.Radio(
|
| 135 |
+
choices=["Ascending", "Descending"],
|
| 136 |
+
label="Sort Order",
|
| 137 |
+
value="Ascending"
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
clear_btn = gr.Button("Clear Filters")
|
| 141 |
+
|
| 142 |
+
with gr.Column(scale=3):
|
| 143 |
+
data_table = gr.Dataframe(
|
| 144 |
+
value=table_data[table_names[0]] if table_names else pd.DataFrame(),
|
| 145 |
+
label="Table Data",
|
| 146 |
+
interactive=False,
|
| 147 |
+
wrap=True,
|
| 148 |
+
height=600
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Event handlers
|
| 152 |
+
def update_table(table_name, search, col_filter, sort_col, sort_ord):
|
| 153 |
+
filtered_df = get_filtered_data(table_name, search, col_filter, sort_col, sort_ord)
|
| 154 |
+
info = get_table_info(table_name)
|
| 155 |
+
return filtered_df, info
|
| 156 |
+
|
| 157 |
+
# Update columns when table changes
|
| 158 |
+
table_selector.change(
|
| 159 |
+
fn=update_column_choices,
|
| 160 |
+
inputs=[table_selector],
|
| 161 |
+
outputs=[column_filter, sort_column]
|
| 162 |
+
).then(
|
| 163 |
+
fn=update_table,
|
| 164 |
+
inputs=[table_selector, search_box, column_filter, sort_column, sort_order],
|
| 165 |
+
outputs=[data_table, table_info]
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Update table when filters/sorting change
|
| 169 |
+
for component in [search_box, column_filter, sort_column, sort_order]:
|
| 170 |
+
component.change(
|
| 171 |
+
fn=update_table,
|
| 172 |
+
inputs=[table_selector, search_box, column_filter, sort_column, sort_order],
|
| 173 |
+
outputs=[data_table, table_info]
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# Clear filters
|
| 177 |
+
def clear_filters():
|
| 178 |
+
return "", "All", "", "Ascending"
|
| 179 |
+
|
| 180 |
+
clear_btn.click(
|
| 181 |
+
fn=clear_filters,
|
| 182 |
+
outputs=[search_box, column_filter, sort_column, sort_order]
|
| 183 |
+
).then(
|
| 184 |
+
fn=update_table,
|
| 185 |
+
inputs=[table_selector, search_box, column_filter, sort_column, sort_order],
|
| 186 |
+
outputs=[data_table, table_info]
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
if __name__ == "__main__":
|
| 190 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==6.1.0
|
| 2 |
+
pandas
|
| 3 |
+
huggingface_hub
|