Lesterchia174 commited on
Commit
ca45592
Β·
verified Β·
1 Parent(s): aefa89a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -27
app.py CHANGED
@@ -109,23 +109,23 @@ def load_models():
109
  models['xgboost'] = create_dummy_model("xgboost")
110
 
111
  # Try to load Linear Regression model
112
- try:
113
- linear_path = hf_hub_download(
114
- repo_id="Lesterchia174/HDB_Price_Predictor",
115
- filename="linear_regression.joblib",
116
- repo_type="space"
117
- )
118
- models['linear_regression'] = safe_joblib_load(linear_path)
119
- if models['linear_regression'] is None:
120
- print("⚠️ Creating dummy model for Linear Regression")
121
- models['linear_regression'] = create_dummy_model("linear_regression")
122
- else:
123
- print("βœ… Linear Regression model loaded and validated")
124
 
125
- except Exception as e:
126
- print(f"❌ Error downloading Linear Regression model: {e}")
127
- print("⚠️ Creating dummy model for Linear Regression")
128
- models['linear_regression'] = create_dummy_model("linear_regression")
129
 
130
  return models
131
 
@@ -237,11 +237,11 @@ def create_market_insights_chart(data, user_input, predicted_price_xgb, predicte
237
  line=dict(width=2, color='darkred')),
238
  name='XGBoost Prediction'))
239
 
240
- fig.add_trace(go.Scatter(x=[user_input['floor_area_sqm']], y=[predicted_price_lr],
241
- mode='markers',
242
- marker=dict(symbol='diamond', size=20, color='blue',
243
- line=dict(width=2, color='darkblue')),
244
- name='Linear Regression Prediction'))
245
 
246
  fig.update_layout(template="plotly_white", height=400, showlegend=True)
247
  return fig
@@ -268,11 +268,11 @@ def predict_hdb_price(town, flat_type, flat_model, floor_area_sqm, storey_level,
268
  print(f"❌ XGBoost prediction error: {e}")
269
  predicted_price_xgb = 400000 # Fallback value
270
 
271
- try:
272
- predicted_price_lr = max(0, float(models['linear_regression'].predict(processed_input)[0]))
273
- except Exception as e:
274
- print(f"❌ Linear Regression prediction error: {e}")
275
- predicted_price_lr = 380000 # Fallback value
276
 
277
  # Use selected model's prediction
278
  if model_choice == "XGBoost":
@@ -362,7 +362,7 @@ with gr.Blocks(title="🏠 HDB Price Predictor", theme=gr.themes.Soft()) as demo
362
  insights = gr.Markdown(label="πŸ“‹ Property Summary")
363
 
364
  with gr.Row():
365
- chart_output = gr.Plot(label="πŸ“ˆ Market Insights (Both Models)")
366
 
367
  # Connect button to function
368
  predict_btn.click(
 
109
  models['xgboost'] = create_dummy_model("xgboost")
110
 
111
  # Try to load Linear Regression model
112
+ #try:
113
+ # linear_path = hf_hub_download(
114
+ # repo_id="Lesterchia174/HDB_Price_Predictor",
115
+ # filename="linear_regression.joblib",
116
+ # repo_type="space"
117
+ # )
118
+ # models['linear_regression'] = safe_joblib_load(linear_path)
119
+ # if models['linear_regression'] is None:
120
+ # print("⚠️ Creating dummy model for Linear Regression")
121
+ # models['linear_regression'] = create_dummy_model("linear_regression")
122
+ # else:
123
+ # print("βœ… Linear Regression model loaded and validated")
124
 
125
+ #except Exception as e:
126
+ # print(f"❌ Error downloading Linear Regression model: {e}")
127
+ # print("⚠️ Creating dummy model for Linear Regression")
128
+ # models['linear_regression'] = create_dummy_model("linear_regression")
129
 
130
  return models
131
 
 
237
  line=dict(width=2, color='darkred')),
238
  name='XGBoost Prediction'))
239
 
240
+ #fig.add_trace(go.Scatter(x=[user_input['floor_area_sqm']], y=[predicted_price_lr],
241
+ # mode='markers',
242
+ # marker=dict(symbol='diamond', size=20, color='blue',
243
+ # line=dict(width=2, color='darkblue')),
244
+ # name='Linear Regression Prediction'))
245
 
246
  fig.update_layout(template="plotly_white", height=400, showlegend=True)
247
  return fig
 
268
  print(f"❌ XGBoost prediction error: {e}")
269
  predicted_price_xgb = 400000 # Fallback value
270
 
271
+ #try:
272
+ # predicted_price_lr = max(0, float(models['linear_regression'].predict(processed_input)[0]))
273
+ #except Exception as e:
274
+ # print(f"❌ Linear Regression prediction error: {e}")
275
+ # predicted_price_lr = 380000 # Fallback value
276
 
277
  # Use selected model's prediction
278
  if model_choice == "XGBoost":
 
362
  insights = gr.Markdown(label="πŸ“‹ Property Summary")
363
 
364
  with gr.Row():
365
+ chart_output = gr.Plot(label="πŸ“ˆ Market Insights")
366
 
367
  # Connect button to function
368
  predict_btn.click(