Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,8 @@ def clean_data(df):
|
|
| 39 |
|
| 40 |
def upload_file(file):
|
| 41 |
global df_global
|
|
|
|
|
|
|
| 42 |
ext = os.path.splitext(file.name)[-1]
|
| 43 |
df = pd.read_csv(file.name) if ext == ".csv" else pd.read_excel(file.name)
|
| 44 |
df = clean_data(df)
|
|
@@ -153,8 +155,8 @@ with gr.Blocks() as demo:
|
|
| 153 |
with gr.Row():
|
| 154 |
with gr.Column():
|
| 155 |
file_input = gr.File(label="Upload CSV or Excel", type="filepath")
|
| 156 |
-
upload_btn = gr.Button("Upload & Clean")
|
| 157 |
df_output = gr.DataFrame(label="Cleaned Data Preview")
|
|
|
|
| 158 |
|
| 159 |
with gr.Column():
|
| 160 |
insights_output = gr.Textbox(label="Insights from SmolAgent", lines=15)
|
|
@@ -170,7 +172,6 @@ with gr.Blocks() as demo:
|
|
| 170 |
shap_img = gr.Image(label="SHAP Summary Plot")
|
| 171 |
lime_img = gr.Image(label="LIME Explanation")
|
| 172 |
|
| 173 |
-
upload_btn.click(fn=upload_file, inputs=file_input, outputs=df_output)
|
| 174 |
agent_btn.click(fn=run_agent, inputs=df_output, outputs=insights_output)
|
| 175 |
train_btn.click(fn=train_model, inputs=df_output, outputs=[metrics_output, trials_output])
|
| 176 |
explain_btn.click(fn=explainability, inputs=df_output, outputs=[shap_img, lime_img])
|
|
|
|
| 39 |
|
| 40 |
def upload_file(file):
|
| 41 |
global df_global
|
| 42 |
+
if file is None:
|
| 43 |
+
return pd.DataFrame({"Error": ["No file uploaded."]})
|
| 44 |
ext = os.path.splitext(file.name)[-1]
|
| 45 |
df = pd.read_csv(file.name) if ext == ".csv" else pd.read_excel(file.name)
|
| 46 |
df = clean_data(df)
|
|
|
|
| 155 |
with gr.Row():
|
| 156 |
with gr.Column():
|
| 157 |
file_input = gr.File(label="Upload CSV or Excel", type="filepath")
|
|
|
|
| 158 |
df_output = gr.DataFrame(label="Cleaned Data Preview")
|
| 159 |
+
file_input.change(fn=upload_file, inputs=file_input, outputs=df_output)
|
| 160 |
|
| 161 |
with gr.Column():
|
| 162 |
insights_output = gr.Textbox(label="Insights from SmolAgent", lines=15)
|
|
|
|
| 172 |
shap_img = gr.Image(label="SHAP Summary Plot")
|
| 173 |
lime_img = gr.Image(label="LIME Explanation")
|
| 174 |
|
|
|
|
| 175 |
agent_btn.click(fn=run_agent, inputs=df_output, outputs=insights_output)
|
| 176 |
train_btn.click(fn=train_model, inputs=df_output, outputs=[metrics_output, trials_output])
|
| 177 |
explain_btn.click(fn=explainability, inputs=df_output, outputs=[shap_img, lime_img])
|