File size: 1,193 Bytes
3ac0ad2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle

# Load the KNN model from the pickle file
with open('ols_model_results.pkl', 'rb') as f:
    lr_model = pickle.load(f)

# Define the attributes without the intercept
attributes = [
    ("CRIM", (0, 100)),
    ("ZN", (0, 100)),
    ("INDUS", (0, 30)),
    ("CHAS", (0, 1)),
    ("NOX", (0, 1)),
    ("RM", (3, 9)),
    ("DIS", (0, 12)),
    ("RAD", (1, 24)),
    ("TAX", (100, 700)),
    ("PTRATIO", (13, 23)),
    ("LSTAT", (2, 38))
]

# Create a list of Input objects for each attribute
attribute_inputs = [
    gr.Slider(minimum=min_val, maximum=max_val, label=name, default=min_val)
    for name, (min_val, max_val) in attributes
]

# Prediction function
def predict(*args):
    # Always prepend 1.0 to represent the intercept
    input_data = [1.0] + [float(arg) for arg in args]
    predicted_value = lr_model.predict([input_data])[0]
    return f"Predicted value of the house: ${predicted_value * 1000:.2f}"

# The rest of the code to display UI remains the same.

# Create the interface
iface = gr.Interface(fn=predict, inputs=attribute_inputs, outputs="text", live=True)


# Launch the interface

iface.launch(server_name="0.0.0.0", server_port=7860)