Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -204,12 +204,15 @@ def analyze_file(file, label_col, n_clusters):
|
|
| 204 |
|
| 205 |
try:
|
| 206 |
f_scores, _ = f_classif(X_processed, clusters_kmeans)
|
|
|
|
|
|
|
| 207 |
f_series = pd.Series(f_scores, index=X_processed.columns).sort_values(ascending=False).head(MAX_FEATURES_TO_SHOW)
|
| 208 |
plt.figure(figsize=(10, 6))
|
| 209 |
-
sns.barplot(
|
| 210 |
plt.title("Top 10 Differentiating Features (ANOVA F-scores)")
|
| 211 |
plt.xlabel("F-score")
|
| 212 |
plt.ylabel("Feature")
|
|
|
|
| 213 |
buf = io.BytesIO()
|
| 214 |
plt.savefig(buf, format="png", bbox_inches="tight")
|
| 215 |
plt.close()
|
|
@@ -220,11 +223,18 @@ def analyze_file(file, label_col, n_clusters):
|
|
| 220 |
|
| 221 |
return results_text, model_img, fi_img, kmeans_img, agg_img, diff_img
|
| 222 |
|
| 223 |
-
def predict_interactive(
|
| 224 |
if global_data['model'] is None:
|
| 225 |
return "Please analyze a file first to train the model."
|
| 226 |
|
| 227 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
# Create DataFrame from user inputs
|
| 229 |
input_data = pd.DataFrame([kwargs])
|
| 230 |
|
|
@@ -349,7 +359,7 @@ with gr.Blocks() as demo:
|
|
| 349 |
def update_inputs(file, label_col):
|
| 350 |
print(f"Updating inputs with file: {file}, label_col: {label_col}") # Debug logging
|
| 351 |
components = create_interactive_inputs(file, label_col)
|
| 352 |
-
return components, gr.
|
| 353 |
|
| 354 |
file_input.change(
|
| 355 |
fn=update_inputs,
|
|
|
|
| 204 |
|
| 205 |
try:
|
| 206 |
f_scores, _ = f_classif(X_processed, clusters_kmeans)
|
| 207 |
+
# Handle potential division by zero or NaN values
|
| 208 |
+
f_scores = np.nan_to_num(f_scores, nan=0.0, posinf=0.0)
|
| 209 |
f_series = pd.Series(f_scores, index=X_processed.columns).sort_values(ascending=False).head(MAX_FEATURES_TO_SHOW)
|
| 210 |
plt.figure(figsize=(10, 6))
|
| 211 |
+
sns.barplot(data=f_series.reset_index(), x="index", y=0, hue="index", legend=False) # Fix palette warning
|
| 212 |
plt.title("Top 10 Differentiating Features (ANOVA F-scores)")
|
| 213 |
plt.xlabel("F-score")
|
| 214 |
plt.ylabel("Feature")
|
| 215 |
+
plt.xticks(rotation=45)
|
| 216 |
buf = io.BytesIO()
|
| 217 |
plt.savefig(buf, format="png", bbox_inches="tight")
|
| 218 |
plt.close()
|
|
|
|
| 223 |
|
| 224 |
return results_text, model_img, fi_img, kmeans_img, agg_img, diff_img
|
| 225 |
|
| 226 |
+
def predict_interactive(*args):
|
| 227 |
if global_data['model'] is None:
|
| 228 |
return "Please analyze a file first to train the model."
|
| 229 |
|
| 230 |
try:
|
| 231 |
+
# Convert args to kwargs based on column names
|
| 232 |
+
kwargs = {}
|
| 233 |
+
if len(args) > 0 and global_data['X_columns'] is not None:
|
| 234 |
+
for i, col in enumerate(global_data['X_columns']):
|
| 235 |
+
if i < len(args):
|
| 236 |
+
kwargs[col] = args[i]
|
| 237 |
+
|
| 238 |
# Create DataFrame from user inputs
|
| 239 |
input_data = pd.DataFrame([kwargs])
|
| 240 |
|
|
|
|
| 359 |
def update_inputs(file, label_col):
|
| 360 |
print(f"Updating inputs with file: {file}, label_col: {label_col}") # Debug logging
|
| 361 |
components = create_interactive_inputs(file, label_col)
|
| 362 |
+
return components, gr.update(components=components, visible=True) # Use gr.update() instead of gr.Column.update()
|
| 363 |
|
| 364 |
file_input.change(
|
| 365 |
fn=update_inputs,
|