Razzaqi3143 commited on
Commit
7697c7f
·
verified ·
1 Parent(s): cddd42f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the saved model and scaler
6
+ model = joblib.load('best_random_forest_model.pkl')
7
+ scaler = joblib.load('scaler.pkl')
8
+
9
+ def predict_house_price(feature1, feature2, feature3, feature4, feature5):
10
+ # Combine all features into a single list
11
+ features = [feature1, feature2, feature3, feature4, feature5]
12
+
13
+ # Scale the input features using the saved scaler
14
+ scaled_features = scaler.transform([features])
15
+
16
+ # Make predictions using the loaded model
17
+ prediction = model.predict(scaled_features)
18
+
19
+ return f"Predicted House Price: ${prediction[0]:,.2f}"
20
+
21
+ # Create the Gradio interface
22
+ interface = gr.Interface(
23
+ fn=predict_house_price,
24
+ inputs=[
25
+ gr.Number(label="Feature 1: (e.g., Average number of rooms per dwelling)"),
26
+ gr.Number(label="Feature 2: (e.g., Total rooms)"),
27
+ gr.Number(label="Feature 3: (e.g., Total bedrooms)"),
28
+ gr.Number(label="Feature 4: (e.g., Median age of houses)"),
29
+ gr.Number(label="Feature 5: (e.g., Population)"),
30
+ ],
31
+ outputs=gr.Textbox(label="Predicted House Price"),
32
+ description="Predict California house prices based on input features.",
33
+ title="California House Price Predictor"
34
+ )
35
+
36
+ # Launch the Gradio app
37
+ interface.launch()