Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load the pre-trained model
|
| 6 |
+
model = joblib.load("house_price_model.pkl")
|
| 7 |
+
|
| 8 |
+
# Define a prediction function
|
| 9 |
+
def predict_price(area):
|
| 10 |
+
# Convert input to the correct format
|
| 11 |
+
area_array = np.array([[float(area)]]) # Reshape to 2D array
|
| 12 |
+
predicted_price = model.predict(area_array)
|
| 13 |
+
return f"The predicted price for {area} sq ft house is ${predicted_price[0]:,.2f}"
|
| 14 |
+
|
| 15 |
+
# Create a Gradio interface
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=predict_price, # Function to call for predictions
|
| 18 |
+
inputs=gr.Number(label="Enter Area (sq ft)"), # Input field
|
| 19 |
+
outputs=gr.Textbox(label="Predicted Price"), # Output display
|
| 20 |
+
title="House Price Prediction",
|
| 21 |
+
description="Enter the area of a house (in square feet), and this application will predict its price."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the app
|
| 25 |
+
interface.launch()
|