sedrick-keh-tri commited on
Commit
587e3a6
·
1 Parent(s): 737533c

customizable width

Browse files
Files changed (1) hide show
  1. app.py +40 -3
app.py CHANGED
@@ -47,6 +47,16 @@ def load_database_tables(db_path):
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"""
@@ -94,9 +104,13 @@ def get_table_info(table_name):
94
 
95
  return info
96
 
97
- # Create Gradio interface
98
- css = """
99
- /* Aggressive targeting of ALL table cells */
 
 
 
 
100
  table td,
101
  table th {
102
  max-width: 400px !important;
@@ -131,6 +145,29 @@ css = """
131
  }
132
  """
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  with gr.Blocks(title="VLA Foundry Database Viewer", css=css) as demo:
135
  gr.Markdown("# 🤖 VLA Foundry Database Viewer")
136
  gr.Markdown("Explore the VLA Foundry database with searchable, filterable, and sortable tables.")
 
47
  db_path = download_database()
48
  table_data, table_names = load_database_tables(db_path)
49
 
50
+ # Column width configuration (in pixels)
51
+ # Specify widths for specific columns across all tables
52
+ # Format: {"column_name": width_in_px}
53
+ column_widths = {
54
+ # Example configurations - modify these as needed
55
+ # "id": 100,
56
+ # "name": 200,
57
+ # "description": 400,
58
+ }
59
+
60
  # Function to get table data with filters
61
  def get_filtered_data(table_name, search_query="", column_filter="All", sort_column="", sort_order="Ascending"):
62
  """Get filtered and sorted data from selected table"""
 
104
 
105
  return info
106
 
107
+ # Generate CSS with custom column widths
108
+ def generate_css():
109
+ """Generate CSS with custom column widths based on column_widths config"""
110
+
111
+ # Base CSS
112
+ base_css = """
113
+ /* Default table cell styling */
114
  table td,
115
  table th {
116
  max-width: 400px !important;
 
145
  }
146
  """
147
 
148
+ # Add custom column widths using nth-child selectors
149
+ custom_css = ""
150
+ if table_data and table_names:
151
+ for table_name in table_names:
152
+ if table_name in table_data:
153
+ df = table_data[table_name]
154
+ for idx, col_name in enumerate(df.columns):
155
+ if col_name in column_widths:
156
+ width = column_widths[col_name]
157
+ # nth-child is 1-indexed
158
+ custom_css += f"""
159
+ table td:nth-child({idx + 1}),
160
+ table th:nth-child({idx + 1}) {{
161
+ width: {width}px !important;
162
+ min-width: {width}px !important;
163
+ max-width: {width}px !important;
164
+ }}
165
+ """
166
+
167
+ return base_css + custom_css
168
+
169
+ css = generate_css()
170
+
171
  with gr.Blocks(title="VLA Foundry Database Viewer", css=css) as demo:
172
  gr.Markdown("# 🤖 VLA Foundry Database Viewer")
173
  gr.Markdown("Explore the VLA Foundry database with searchable, filterable, and sortable tables.")