Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -351,7 +351,11 @@ def process_dataframe(df):
|
|
| 351 |
]:
|
| 352 |
|
| 353 |
try:
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
except ValueError as e:
|
| 356 |
print(f'inverse transform fails value in column {col}: {e}', 'error')
|
| 357 |
|
|
@@ -383,27 +387,34 @@ def process_dataframe(df):
|
|
| 383 |
# ------------------------------
|
| 384 |
# Report View Route with Pagination & Toggle
|
| 385 |
# ------------------------------
|
| 386 |
-
@app.route('/report')
|
| 387 |
-
def report_view():
|
| 388 |
-
report_type = request.args.get('report_type', 'pred')
|
| 389 |
-
try:
|
| 390 |
-
page = int(request.args.get('page', 1))
|
| 391 |
-
except ValueError:
|
| 392 |
-
page = 1
|
| 393 |
-
per_page = 15 # records per page
|
| 394 |
-
|
| 395 |
-
# Read the appropriate CSV file.
|
| 396 |
-
if report_type == 'pred':
|
| 397 |
-
df = pd.read_csv(PRED_OUTPUT_FILE)
|
| 398 |
-
else:
|
| 399 |
-
df = pd.read_csv(CLASS_OUTPUT_FILE)
|
| 400 |
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
-
df_page = df.iloc[start_idx:end_idx]
|
| 406 |
-
|
| 407 |
# -------------------------------------V Colored CHnages --------------------------------------
|
| 408 |
'''
|
| 409 |
def add_colored_arrow(row):
|
|
@@ -421,8 +432,6 @@ def report_view():
|
|
| 421 |
|
| 422 |
df_page['Makable_Predicted'] = df_page.apply(add_colored_arrow, axis=1)
|
| 423 |
# -------------------------------------V Colored CHnages --------------------------------------
|
| 424 |
-
|
| 425 |
-
|
| 426 |
# # -------------------------------------V Icon CHnages --------------------------------------
|
| 427 |
# def add_fa_icon(row):
|
| 428 |
# try:
|
|
@@ -439,8 +448,7 @@ def report_view():
|
|
| 439 |
|
| 440 |
# df_page['Makable_Predicted'] = df_page.apply(add_fa_icon, axis=1)
|
| 441 |
# # -------------------------------------V Icon CHnages --------------------------------------
|
| 442 |
-
|
| 443 |
-
|
| 444 |
table_html = df_page.to_html(classes="data-table", index=False, escape=False)
|
| 445 |
|
| 446 |
has_prev = page > 1
|
|
@@ -455,26 +463,7 @@ def report_view():
|
|
| 455 |
print("------------------------------------------------------------------------------------------------")
|
| 456 |
print("df_page['Makable_Diff']", df_page['Makable_Diff'])
|
| 457 |
print("------------------------------------------------------------------------------------------------")
|
| 458 |
-
'''
|
| 459 |
-
# ------------------ V changes --------------------------------------
|
| 460 |
-
# Prepare chart data (convert to JSON for JS)
|
| 461 |
-
chart_data = {
|
| 462 |
-
'EngCts': [],
|
| 463 |
-
'Makable_Predicted': [],
|
| 464 |
-
'Makable_Diff': []
|
| 465 |
-
}
|
| 466 |
-
|
| 467 |
-
# ------------------ V changes --------------------------------------
|
| 468 |
-
|
| 469 |
-
return render_template('output.html',
|
| 470 |
-
table_html=table_html,
|
| 471 |
-
report_type=report_type,
|
| 472 |
-
page=page,
|
| 473 |
-
has_prev=has_prev,
|
| 474 |
-
has_next=has_next,
|
| 475 |
-
chart_data=json.dumps(chart_data)
|
| 476 |
-
)
|
| 477 |
-
|
| 478 |
|
| 479 |
# ------------------------------
|
| 480 |
# Download Routes
|
|
|
|
| 351 |
]:
|
| 352 |
|
| 353 |
try:
|
| 354 |
+
def safe_inverse_transform(le: LabelEncoder, codes: np.ndarray):
|
| 355 |
+
known = set(le.classes_)
|
| 356 |
+
return np.array([le.inverse_transform([c])[0] if c in known else "Unknown" for c in codes])
|
| 357 |
+
df_pred_main[col] = safe_inverse_transform(loaded_label_encoder[col], df_pred_0[col])
|
| 358 |
+
#df_pred_main[col] = loaded_label_encoder[col].inverse_transform(df_pred_main[col].astype(int))
|
| 359 |
except ValueError as e:
|
| 360 |
print(f'inverse transform fails value in column {col}: {e}', 'error')
|
| 361 |
|
|
|
|
| 387 |
# ------------------------------
|
| 388 |
# Report View Route with Pagination & Toggle
|
| 389 |
# ------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
+
@app.route("/report")
|
| 392 |
+
def report_view():
|
| 393 |
+
# 1. get your input features
|
| 394 |
+
X_new = ... # DataFrame
|
| 395 |
+
|
| 396 |
+
# 2. predict
|
| 397 |
+
codes = model.predict(X_new)
|
| 398 |
+
labels = safe_inverse_transform(label_enc, codes)
|
| 399 |
+
|
| 400 |
+
# 3. build df & html
|
| 401 |
+
df = pd.DataFrame({
|
| 402 |
+
"EngCts": X_new["EngCts"],
|
| 403 |
+
"Makable_Predicted": labels,
|
| 404 |
+
"Makable_Diff": X_new["EngCts"].astype(float) - label_enc.transform(labels)
|
| 405 |
+
})
|
| 406 |
+
|
| 407 |
+
table_html = df.to_html(classes="report-table", index=False)
|
| 408 |
+
|
| 409 |
+
return render_template(
|
| 410 |
+
"output.html",
|
| 411 |
+
report_type="pred",
|
| 412 |
+
page=1,
|
| 413 |
+
has_prev=False,
|
| 414 |
+
has_next=False,
|
| 415 |
+
table_html=table_html
|
| 416 |
+
)
|
| 417 |
|
|
|
|
|
|
|
| 418 |
# -------------------------------------V Colored CHnages --------------------------------------
|
| 419 |
'''
|
| 420 |
def add_colored_arrow(row):
|
|
|
|
| 432 |
|
| 433 |
df_page['Makable_Predicted'] = df_page.apply(add_colored_arrow, axis=1)
|
| 434 |
# -------------------------------------V Colored CHnages --------------------------------------
|
|
|
|
|
|
|
| 435 |
# # -------------------------------------V Icon CHnages --------------------------------------
|
| 436 |
# def add_fa_icon(row):
|
| 437 |
# try:
|
|
|
|
| 448 |
|
| 449 |
# df_page['Makable_Predicted'] = df_page.apply(add_fa_icon, axis=1)
|
| 450 |
# # -------------------------------------V Icon CHnages --------------------------------------
|
| 451 |
+
|
|
|
|
| 452 |
table_html = df_page.to_html(classes="data-table", index=False, escape=False)
|
| 453 |
|
| 454 |
has_prev = page > 1
|
|
|
|
| 463 |
print("------------------------------------------------------------------------------------------------")
|
| 464 |
print("df_page['Makable_Diff']", df_page['Makable_Diff'])
|
| 465 |
print("------------------------------------------------------------------------------------------------")
|
| 466 |
+
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
|
| 468 |
# ------------------------------
|
| 469 |
# Download Routes
|