broadfield-dev commited on
Commit
5d15c84
·
verified ·
1 Parent(s): 2a4d2b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -41,7 +41,7 @@ def get_user_datasets(username: str):
41
  return gr.Dropdown.update(choices=sorted(dataset_ids), value=None, interactive=True)
42
  except Exception as e:
43
  gr.Warning(f"Could not fetch datasets for user '{username}'. Error: {e}")
44
- return gr.Dropdown.update(choices=[], value=None, interactive=False)
45
 
46
  def get_dataset_splits(dataset_id: str):
47
  """Gets all available splits for a selected dataset."""
@@ -52,12 +52,12 @@ def get_dataset_splits(dataset_id: str):
52
  return gr.Dropdown.update(choices=splits, value=splits[0] if splits else None, interactive=True)
53
  except Exception as e:
54
  gr.Warning(f"Could not fetch splits for dataset '{dataset_id}'. Error: {e}")
55
- return gr.Dropdown.update(choices=[], value=None, interactive=False)
56
 
57
  def get_split_columns(dataset_id: str, split: str):
58
  """Gets all columns for a selected split by loading one row."""
59
  if not dataset_id or not split:
60
- return gr.Dropdown.update(choices=[], value=None, interactive=False)
61
  try:
62
  # Stream one row to get column names without downloading the whole dataset
63
  dataset_sample = load_dataset(dataset_id, split=split, streaming=True)
@@ -66,10 +66,10 @@ def get_split_columns(dataset_id: str, split: str):
66
  # Heuristically find the best text column
67
  preferred_cols = ['text', 'content', 'instruction', 'question', 'document', 'prompt']
68
  best_col = next((col for col in preferred_cols if col in columns), columns[0] if columns else None)
69
- return gr.Dropdown.update(choices=columns, value=best_col, interactive=True)
70
  except Exception as e:
71
  gr.Warning(f"Could not fetch columns for split '{split}'. Error: {e}")
72
- return gr.Dropdown.update(choices=[], value=None, interactive=False)
73
 
74
  # --- Main Atlas Generation Logic ---
75
  def generate_atlas(
 
41
  return gr.Dropdown.update(choices=sorted(dataset_ids), value=None, interactive=True)
42
  except Exception as e:
43
  gr.Warning(f"Could not fetch datasets for user '{username}'. Error: {e}")
44
+ return gr.update(choices=[], value=None, interactive=False)
45
 
46
  def get_dataset_splits(dataset_id: str):
47
  """Gets all available splits for a selected dataset."""
 
52
  return gr.Dropdown.update(choices=splits, value=splits[0] if splits else None, interactive=True)
53
  except Exception as e:
54
  gr.Warning(f"Could not fetch splits for dataset '{dataset_id}'. Error: {e}")
55
+ return gr.update(choices=[], value=None, interactive=False)
56
 
57
  def get_split_columns(dataset_id: str, split: str):
58
  """Gets all columns for a selected split by loading one row."""
59
  if not dataset_id or not split:
60
+ return gr.update(choices=[], value=None, interactive=False)
61
  try:
62
  # Stream one row to get column names without downloading the whole dataset
63
  dataset_sample = load_dataset(dataset_id, split=split, streaming=True)
 
66
  # Heuristically find the best text column
67
  preferred_cols = ['text', 'content', 'instruction', 'question', 'document', 'prompt']
68
  best_col = next((col for col in preferred_cols if col in columns), columns[0] if columns else None)
69
+ return gr.update(choices=columns, value=best_col, interactive=True)
70
  except Exception as e:
71
  gr.Warning(f"Could not fetch columns for split '{split}'. Error: {e}")
72
+ return gr.update(choices=[], value=None, interactive=False)
73
 
74
  # --- Main Atlas Generation Logic ---
75
  def generate_atlas(