Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
# Define input components for housing price prediction
|
5 |
+
input_module1 = gr.Slider(minimum=500, maximum=5000, step=100, label="Square Footage") # Slider for square footage
|
6 |
+
input_module2 = gr.Slider(minimum=1, maximum=10, step=1, label="Number of Bedrooms") # Slider for number of bedrooms
|
7 |
+
input_module3 = gr.Dropdown(choices=["Urban", "Suburban", "Rural"], label="Location") # Dropdown for location
|
8 |
+
input_module4 = gr.Checkbox(label="Has Garden") # Checkbox for garden
|
9 |
+
input_module5 = gr.Checkbox(label="Has Garage") # Checkbox for garage
|
10 |
+
|
11 |
+
# Define output components
|
12 |
+
output_module1 = gr.Textbox(label="Predicted Price") # Textbox for predicted price
|
13 |
+
output_module2 = gr.Textbox(label="Prediction Explanation") # Textbox for explanation
|
14 |
+
|
15 |
+
# Function for housing price prediction (simulate with random values)
|
16 |
+
def predict_price(square_footage, num_bedrooms, location, has_garden, has_garage):
|
17 |
+
price = square_footage * 200 + num_bedrooms * 50000 # Simplified formula
|
18 |
+
if location == "Urban":
|
19 |
+
price *= 1.5
|
20 |
+
if has_garden:
|
21 |
+
price += 20000
|
22 |
+
if has_garage:
|
23 |
+
price += 15000
|
24 |
+
|
25 |
+
explanation = f"Based on {square_footage} sqft, {num_bedrooms} bedrooms, location {location}, garden: {has_garden}, garage: {has_garage}, the predicted price is ${price:.2f}."
|
26 |
+
|
27 |
+
return f"${price:.2f}", explanation
|
28 |
+
|
29 |
+
# Launch the Gradio interface for housing price prediction
|
30 |
+
gr.Interface(fn=predict_price,
|
31 |
+
inputs=[input_module1, input_module2, input_module3,
|
32 |
+
input_module4, input_module5],
|
33 |
+
outputs=[output_module1, output_module2]).launch()
|