Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,32 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
|
| 4 |
+
# Load your trained model (replace with the actual path)
|
| 5 |
+
model = LinearRegression() # Assuming you saved the model
|
| 6 |
+
model.load("rmaitest/housepricepridiction.pkl") # Replace with the path
|
| 7 |
|
| 8 |
+
def predict(size, bedrooms, age):
|
| 9 |
+
"""Predicts house price based on input features."""
|
| 10 |
+
# Create a DataFrame from user input
|
| 11 |
+
input_data = pd.DataFrame({
|
| 12 |
+
'Size (sq ft)': [size],
|
| 13 |
+
'Number of Bedrooms': [bedrooms],
|
| 14 |
+
'Age of House (years)': [age]
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
# Predict the price using the trained model
|
| 18 |
+
predicted_price = model.predict(input_data)[0]
|
| 19 |
+
|
| 20 |
+
# Format the output with dollar sign and two decimal places
|
| 21 |
+
return f"Predicted Price: ${predicted_price:,.2f}"
|
| 22 |
+
|
| 23 |
+
# Create the Gradio interface
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=predict,
|
| 26 |
+
inputs=["number", "number", "number"], # Three numeric input fields
|
| 27 |
+
outputs="text", # Output is the predicted price (text)
|
| 28 |
+
title="House Price Prediction",
|
| 29 |
+
description="Enter house details to predict the price."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch(share=True)
|