Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import joblib
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
|
| 7 |
+
housing = pd.read_csv('housing.csv')
|
| 8 |
+
model = joblib.load('housing_model.pkl')
|
| 9 |
+
|
| 10 |
+
def predict_price(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
|
| 11 |
+
features = np.array([[longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income]])
|
| 12 |
+
prediction = model.predict(features)
|
| 13 |
+
return prediction[0]
|
| 14 |
+
def predict_plot(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
|
| 15 |
+
prediction = predict_price(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income)
|
| 16 |
+
|
| 17 |
+
sc = housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.4,
|
| 18 |
+
s=housing["population"]/100, label="population", figsize=(10,7),
|
| 19 |
+
c="median_house_value", cmap=plt.get_cmap("jet"), colorbar=True,
|
| 20 |
+
sharex=False, title = "Predicted Housing Price")
|
| 21 |
+
sc.scatter(longitude, latitude, s=250, c="red", marker="X", label = "Your Input")
|
| 22 |
+
plt.legend()
|
| 23 |
+
fig = sc.get_figure()
|
| 24 |
+
return prediction, fig
|
| 25 |
+
|
| 26 |
+
input1 = gr.Slider(value = -125, minimum=-125, maximum=-114, step = 0.01, label="Longitude")
|
| 27 |
+
input2 = gr.Slider(value = 32, minimum=32, maximum=42, step = 0.01, label="Latitude")
|
| 28 |
+
input3 = gr.Slider(value = 1, minimum=1, maximum=52, step = 1, label="Housing Median Age")
|
| 29 |
+
input4 = gr.Number(label = "Total Rooms")
|
| 30 |
+
input5 = gr.Number(label = "Total Bedrooms")
|
| 31 |
+
input6 = gr.Number(label = "Population")
|
| 32 |
+
input7 = gr.Number(label = "Households")
|
| 33 |
+
input8 = gr.Slider(value = 0,minimum=0, maximum=15,step = 0.1, label = "Median Income")
|
| 34 |
+
|
| 35 |
+
gr.Interface(predict_plot, [input1, input2, input3, input4, input5, input6, input7, input8], outputs = [gr.Textbox(label="prediction"), gr.Plot(label="Scatter Plot")], title = "Housing Price Prediction").launch()
|