Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,6 +22,7 @@ from sklearn.linear_model import LinearRegression
|
|
| 22 |
from sklearn.tree import DecisionTreeRegressor
|
| 23 |
from sklearn.ensemble import RandomForestRegressor
|
| 24 |
from sklearn.svm import SVR
|
|
|
|
| 25 |
|
| 26 |
# Metrics
|
| 27 |
from sklearn.metrics import (
|
|
@@ -68,6 +69,25 @@ def load_boston():
|
|
| 68 |
# MAIN FUNCTION
|
| 69 |
# =====================================================
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def run_models(task_type, dataset_name):
|
| 72 |
|
| 73 |
# =========================
|
|
@@ -194,7 +214,8 @@ def run_models(task_type, dataset_name):
|
|
| 194 |
"Model"
|
| 195 |
]
|
| 196 |
|
| 197 |
-
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
# =====================================================
|
|
@@ -262,10 +283,12 @@ with gr.Blocks() as demo:
|
|
| 262 |
|
| 263 |
output_text = gr.Textbox()
|
| 264 |
|
|
|
|
|
|
|
| 265 |
run_button.click(
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
)
|
| 270 |
|
| 271 |
demo.launch()
|
|
|
|
| 22 |
from sklearn.tree import DecisionTreeRegressor
|
| 23 |
from sklearn.ensemble import RandomForestRegressor
|
| 24 |
from sklearn.svm import SVR
|
| 25 |
+
from sklearn.svm import SVC
|
| 26 |
|
| 27 |
# Metrics
|
| 28 |
from sklearn.metrics import (
|
|
|
|
| 69 |
# MAIN FUNCTION
|
| 70 |
# =====================================================
|
| 71 |
|
| 72 |
+
|
| 73 |
+
def save_report(results_df, best_model, task_type, dataset_name):
|
| 74 |
+
file_path = "model_report.txt"
|
| 75 |
+
|
| 76 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 77 |
+
f.write("AI Model Comparison Report\n")
|
| 78 |
+
f.write("=" * 40 + "\n\n")
|
| 79 |
+
|
| 80 |
+
f.write(f"Task Type: {task_type}\n")
|
| 81 |
+
f.write(f"Dataset: {dataset_name}\n\n")
|
| 82 |
+
|
| 83 |
+
f.write("Results:\n")
|
| 84 |
+
f.write(results_df.to_string(index=False))
|
| 85 |
+
f.write("\n\n")
|
| 86 |
+
|
| 87 |
+
f.write(f"Best Model: {best_model}\n")
|
| 88 |
+
|
| 89 |
+
return file_path
|
| 90 |
+
|
| 91 |
def run_models(task_type, dataset_name):
|
| 92 |
|
| 93 |
# =========================
|
|
|
|
| 214 |
"Model"
|
| 215 |
]
|
| 216 |
|
| 217 |
+
report_file = save_report(results_df, best_model, task_type, dataset_name)
|
| 218 |
+
return results_df, f"🏆 Best Model: {best_model}", report_file
|
| 219 |
|
| 220 |
|
| 221 |
# =====================================================
|
|
|
|
| 283 |
|
| 284 |
output_text = gr.Textbox()
|
| 285 |
|
| 286 |
+
output_file = gr.File(label="Download Report")
|
| 287 |
+
|
| 288 |
run_button.click(
|
| 289 |
+
fn=run_models,
|
| 290 |
+
inputs=[task_type, dataset_name],
|
| 291 |
+
outputs=[output_table, output_text, output_file]
|
| 292 |
)
|
| 293 |
|
| 294 |
demo.launch()
|