File size: 1,635 Bytes
76a416c
 
 
 
a140c46
 
 
 
732bb5e
76a416c
 
2f8142e
 
 
 
 
 
 
 
76a416c
 
 
dd8b9c6
76a416c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcc09bd
76a416c
a140c46
76a416c
a140c46
76a416c
732bb5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
import pandas as pd 
import numpy as np 


import pickle
with open("linear_regression_model.pkl", "rb") as file:
    lin_reg = pickle.load(file)

# define the input module 
inputs = [
    gr.components.Number(label="Longitude"),
    gr.components.Number(label="Latitude"),
    gr.components.Number(label="Housing Median Age"),
    gr.components.Number(label="Total Rooms"),
    gr.components.Number(label="Total Bedrooms"),
    gr.components.Number(label="Population"),
    gr.components.Number(label="Households"),
    gr.components.Number(label="Median Income")
]

# define the output module 
outputs = gr.components.Textbox(label = 'Output')


# define the backend function 
from sklearn.preprocessing import MinMaxScaler
def predict_price(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
    features = pd.DataFrame({
        'longitude': [longitude],
        'latitude': [latitude],
        'housing_median_age': [housing_median_age],
        'total_rooms': [total_rooms],
        'total_bedrooms': [total_bedrooms],
        'population': [population],
        'households': [households],
        'median_income': [median_income]
    })

    scaler = MinMaxScaler() ## define the transformer
    # load your scaler from the training dataset 

    features=scaler.fit_transform(features)
    linear_regression_prediction = lin_reg.predict(features)[0]
    #decision_tree_prediction = tree_reg.predict(features)[0]

    return linear_regression_prediction

interface = gr.Interface(fn=predict_price, inputs=inputs, outputs=outputs).launch(debug=True)