Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,30 +14,24 @@ from sklearn.linear_model import LogisticRegression
|
|
| 14 |
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, roc_auc_score
|
| 15 |
import gradio as gr
|
| 16 |
|
| 17 |
-
|
| 18 |
-
def load_csv(file_obj):
|
| 19 |
try:
|
| 20 |
-
|
| 21 |
-
df = pd.read_csv(file_obj)
|
| 22 |
except Exception as e:
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
df = pd.read_excel(file_obj)
|
| 26 |
except Exception as e2:
|
| 27 |
-
return None, f"Failed to read file
|
| 28 |
return df, None
|
| 29 |
|
| 30 |
-
|
| 31 |
-
# Step 1: upload file -> return column choices
|
| 32 |
def on_upload(file):
|
| 33 |
if file is None:
|
| 34 |
return gr.Dropdown.update(choices=[]), "No file uploaded", None
|
| 35 |
-
df, err = load_csv(file)
|
| 36 |
if err:
|
| 37 |
return gr.Dropdown.update(choices=[]), f"Error: {err}", None
|
| 38 |
cols = df.columns.tolist()
|
| 39 |
-
return gr.Dropdown.update(choices=cols, value=cols[-1] if len(cols)>0 else None), f"Loaded {len(df)} rows, {len(cols)} columns", df
|
| 40 |
-
|
| 41 |
|
| 42 |
# Helper: build preprocessing + model pipeline
|
| 43 |
def build_pipeline(df, target_col, impute_strategy, apply_scaling, encode_categorical):
|
|
|
|
| 14 |
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, roc_auc_score
|
| 15 |
import gradio as gr
|
| 16 |
|
| 17 |
+
def load_csv(file_path):
|
|
|
|
| 18 |
try:
|
| 19 |
+
df = pd.read_csv(file_path)
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
try:
|
| 22 |
+
df = pd.read_excel(file_path)
|
|
|
|
| 23 |
except Exception as e2:
|
| 24 |
+
return None, f"Failed to read file: {e} / {e2}"
|
| 25 |
return df, None
|
| 26 |
|
|
|
|
|
|
|
| 27 |
def on_upload(file):
|
| 28 |
if file is None:
|
| 29 |
return gr.Dropdown.update(choices=[]), "No file uploaded", None
|
| 30 |
+
df, err = load_csv(file.name) # file.name = temp file path
|
| 31 |
if err:
|
| 32 |
return gr.Dropdown.update(choices=[]), f"Error: {err}", None
|
| 33 |
cols = df.columns.tolist()
|
| 34 |
+
return gr.Dropdown.update(choices=cols, value=cols[-1] if len(cols) > 0 else None), f"Loaded {len(df)} rows, {len(cols)} columns", df
|
|
|
|
| 35 |
|
| 36 |
# Helper: build preprocessing + model pipeline
|
| 37 |
def build_pipeline(df, target_col, impute_strategy, apply_scaling, encode_categorical):
|