Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -67,13 +67,11 @@ def get_split_columns(dataset_id: str, split: str):
|
|
67 |
if not dataset_id or not split:
|
68 |
return gr.update(choices=[], value=None, interactive=False)
|
69 |
try:
|
70 |
-
# This is the most robust method: stream one row and get its keys.
|
71 |
dataset_sample = load_dataset(dataset_id, split=split, streaming=True)
|
72 |
first_row = next(iter(dataset_sample))
|
73 |
columns = list(first_row.keys())
|
74 |
logging.info(f"Found columns: {columns}")
|
75 |
|
76 |
-
# Heuristically find the best text column
|
77 |
preferred_cols = ['text', 'content', 'instruction', 'question', 'document', 'prompt']
|
78 |
best_col = next((col for col in preferred_cols if col in columns), columns[0] if columns else None)
|
79 |
logging.info(f"Best default column chosen: {best_col}")
|
@@ -144,7 +142,10 @@ def generate_atlas(
|
|
144 |
mount_path = f"/{uuid.uuid4().hex}"
|
145 |
atlas_app = make_server(atlas_dataset, static_path=static_path, duckdb_uri="wasm")
|
146 |
|
147 |
-
|
|
|
|
|
|
|
148 |
|
149 |
progress(1.0, desc="Done!")
|
150 |
iframe_html = f"<iframe src='{mount_path}' width='100%' height='800px' frameborder='0'></iframe>"
|
@@ -177,12 +178,12 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Embedding Atlas Explorer") as app:
|
|
177 |
gr.Markdown("### 3. Explore Atlas")
|
178 |
output_html = gr.HTML("<div style='display:flex; justify-content:center; align-items:center; height:800px; border: 1px solid #ddd; border-radius: 5px;'><p>Atlas will be displayed here after generation.</p></div>")
|
179 |
|
180 |
-
# --- Chained Event Listeners for Dynamic UI (
|
181 |
hf_user_input.submit(fn=get_user_datasets, inputs=hf_user_input, outputs=dataset_input)
|
182 |
|
183 |
dataset_input.change(fn=get_dataset_splits, inputs=dataset_input, outputs=split_input)
|
184 |
|
185 |
-
#
|
186 |
split_input.change(fn=get_split_columns, inputs=[dataset_input, split_input], outputs=text_column_input)
|
187 |
|
188 |
# --- Button Click Event ---
|
|
|
67 |
if not dataset_id or not split:
|
68 |
return gr.update(choices=[], value=None, interactive=False)
|
69 |
try:
|
|
|
70 |
dataset_sample = load_dataset(dataset_id, split=split, streaming=True)
|
71 |
first_row = next(iter(dataset_sample))
|
72 |
columns = list(first_row.keys())
|
73 |
logging.info(f"Found columns: {columns}")
|
74 |
|
|
|
75 |
preferred_cols = ['text', 'content', 'instruction', 'question', 'document', 'prompt']
|
76 |
best_col = next((col for col in preferred_cols if col in columns), columns[0] if columns else None)
|
77 |
logging.info(f"Best default column chosen: {best_col}")
|
|
|
142 |
mount_path = f"/{uuid.uuid4().hex}"
|
143 |
atlas_app = make_server(atlas_dataset, static_path=static_path, duckdb_uri="wasm")
|
144 |
|
145 |
+
# --- THIS IS THE FINAL FIX ---
|
146 |
+
# Call mount_gradio_app from the gradio module 'gr'
|
147 |
+
# and pass the 'app' Blocks instance as the first argument.
|
148 |
+
gr.mount_gradio_app(app, atlas_app, path=mount_path)
|
149 |
|
150 |
progress(1.0, desc="Done!")
|
151 |
iframe_html = f"<iframe src='{mount_path}' width='100%' height='800px' frameborder='0'></iframe>"
|
|
|
178 |
gr.Markdown("### 3. Explore Atlas")
|
179 |
output_html = gr.HTML("<div style='display:flex; justify-content:center; align-items:center; height:800px; border: 1px solid #ddd; border-radius: 5px;'><p>Atlas will be displayed here after generation.</p></div>")
|
180 |
|
181 |
+
# --- Chained Event Listeners for Dynamic UI (Corrected Logic) ---
|
182 |
hf_user_input.submit(fn=get_user_datasets, inputs=hf_user_input, outputs=dataset_input)
|
183 |
|
184 |
dataset_input.change(fn=get_dataset_splits, inputs=dataset_input, outputs=split_input)
|
185 |
|
186 |
+
# The columns are populated only AFTER a split is chosen.
|
187 |
split_input.change(fn=get_split_columns, inputs=[dataset_input, split_input], outputs=text_column_input)
|
188 |
|
189 |
# --- Button Click Event ---
|