codeboosterstech commited on
Commit
084fa81
·
verified ·
1 Parent(s): db21645

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -1,13 +1,28 @@
1
  import gradio as gr
2
  import joblib
3
- import pandas as pd
4
 
5
- model = joblib.load("model.joblib")
 
6
 
7
- def predict(rm, lstat, ptratio):
8
- df = pd.DataFrame([[rm, lstat, ptratio]], columns=["rm", "lstat", "ptratio"])
9
- return model.predict(df)[0]
 
 
10
 
11
- gr.Interface(fn=predict,
12
- inputs=["number", "number", "number"],
13
- outputs="number").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import joblib
3
+ import numpy as np
4
 
5
+ # Load trained model
6
+ model = joblib.load("model/house_price_model.pkl")
7
 
8
+ # Define prediction function
9
+ def predict_price(rm, lstat, ptratio):
10
+ input_data = np.array([[rm, lstat, ptratio]])
11
+ prediction = model.predict(input_data)[0]
12
+ return round(prediction, 2)
13
 
14
+ # Define Gradio interface
15
+ iface = gr.Interface(
16
+ fn=predict_price,
17
+ inputs=[
18
+ gr.Slider(3.0, 9.0, step=0.1, label="Average Rooms (RM)"),
19
+ gr.Slider(1.0, 40.0, step=0.1, label="Lower Status Population (%) (LSTAT)"),
20
+ gr.Slider(12.0, 22.0, step=0.1, label="Pupil-Teacher Ratio (PTRATIO)")
21
+ ],
22
+ outputs=gr.Number(label="Predicted House Price (in $1000s)"),
23
+ title="🏠 Boston Housing Price Predictor",
24
+ description="Enter the house features to predict the price using a linear regression model.",
25
+ )
26
+
27
+ # Launch app
28
+ iface.launch()