Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def predict_price(size, bedrooms, age):
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
response = requests.post(API_URL, json=payload)
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
# Extract the prediction from the response
|
20 |
-
prediction = result["data"][0]
|
21 |
-
return prediction
|
22 |
-
else:
|
23 |
-
return "Error: Unable to get prediction."
|
24 |
|
25 |
# Define the Gradio interface
|
26 |
iface = gr.Interface(
|
@@ -32,9 +33,12 @@ iface = gr.Interface(
|
|
32 |
],
|
33 |
outputs=gr.Number(label="Predicted Price ($)"),
|
34 |
title="House Price Prediction",
|
35 |
-
description="Enter the size, number of bedrooms, and age of the house to get the predicted price."
|
|
|
|
|
36 |
)
|
37 |
|
38 |
# Launch the interface
|
39 |
if __name__ == "__main__":
|
40 |
iface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
+
import joblib
|
5 |
|
6 |
+
# Load the model
|
7 |
+
repo_id = "rmaitest/mlmodel2"
|
8 |
+
model_file = "house_price_model.pkl" # Adjust as necessary
|
9 |
+
|
10 |
+
# Download and load the model
|
11 |
+
model_path = hf_hub_download(repo_id, model_file)
|
12 |
+
model = joblib.load(model_path)
|
13 |
|
14 |
def predict_price(size, bedrooms, age):
|
15 |
+
# Create a DataFrame from the input
|
16 |
+
input_data = pd.DataFrame({
|
17 |
+
'Size (sq ft)': [size],
|
18 |
+
'Number of Bedrooms': [bedrooms],
|
19 |
+
'Age of House (years)': [age]
|
20 |
+
})
|
|
|
21 |
|
22 |
+
# Make prediction
|
23 |
+
prediction = model.predict(input_data)
|
24 |
+
return prediction[0]
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Define the Gradio interface
|
27 |
iface = gr.Interface(
|
|
|
33 |
],
|
34 |
outputs=gr.Number(label="Predicted Price ($)"),
|
35 |
title="House Price Prediction",
|
36 |
+
description="Enter the size, number of bedrooms, and age of the house to get the predicted price.",
|
37 |
+
# Enable API mode for the Space
|
38 |
+
api_open=True
|
39 |
)
|
40 |
|
41 |
# Launch the interface
|
42 |
if __name__ == "__main__":
|
43 |
iface.launch()
|
44 |
+
|