Spaces:
Sleeping
Sleeping
gridflowai
commited on
Commit
•
3ac0ad2
1
Parent(s):
1fbd1d9
Upload 3 files
Browse files- app.py +44 -0
- ols_model_results.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
|
4 |
+
# Load the KNN model from the pickle file
|
5 |
+
with open('ols_model_results.pkl', 'rb') as f:
|
6 |
+
lr_model = pickle.load(f)
|
7 |
+
|
8 |
+
# Define the attributes without the intercept
|
9 |
+
attributes = [
|
10 |
+
("CRIM", (0, 100)),
|
11 |
+
("ZN", (0, 100)),
|
12 |
+
("INDUS", (0, 30)),
|
13 |
+
("CHAS", (0, 1)),
|
14 |
+
("NOX", (0, 1)),
|
15 |
+
("RM", (3, 9)),
|
16 |
+
("DIS", (0, 12)),
|
17 |
+
("RAD", (1, 24)),
|
18 |
+
("TAX", (100, 700)),
|
19 |
+
("PTRATIO", (13, 23)),
|
20 |
+
("LSTAT", (2, 38))
|
21 |
+
]
|
22 |
+
|
23 |
+
# Create a list of Input objects for each attribute
|
24 |
+
attribute_inputs = [
|
25 |
+
gr.Slider(minimum=min_val, maximum=max_val, label=name, default=min_val)
|
26 |
+
for name, (min_val, max_val) in attributes
|
27 |
+
]
|
28 |
+
|
29 |
+
# Prediction function
|
30 |
+
def predict(*args):
|
31 |
+
# Always prepend 1.0 to represent the intercept
|
32 |
+
input_data = [1.0] + [float(arg) for arg in args]
|
33 |
+
predicted_value = lr_model.predict([input_data])[0]
|
34 |
+
return f"Predicted value of the house: ${predicted_value * 1000:.2f}"
|
35 |
+
|
36 |
+
# The rest of the code to display UI remains the same.
|
37 |
+
|
38 |
+
# Create the interface
|
39 |
+
iface = gr.Interface(fn=predict, inputs=attribute_inputs, outputs="text", live=True)
|
40 |
+
|
41 |
+
|
42 |
+
# Launch the interface
|
43 |
+
|
44 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
ols_model_results.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:320708a8aec5e3e41f2aebec138e250dd5e7eabc2ddaa1cf711985349cc770c2
|
3 |
+
size 158478
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
scikit-learn==1.2.2
|
3 |
+
numpy
|
4 |
+
statsmodels==0.14.0
|