File size: 1,647 Bytes
ff6c981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import numpy as np

# Define input components for housing price prediction
input_module1 = gr.Slider(minimum=500, maximum=5000, step=100, label="Square Footage")  # Slider for square footage
input_module2 = gr.Slider(minimum=1, maximum=10, step=1, label="Number of Bedrooms")  # Slider for number of bedrooms
input_module3 = gr.Dropdown(choices=["Urban", "Suburban", "Rural"], label="Location")  # Dropdown for location
input_module4 = gr.Checkbox(label="Has Garden")  # Checkbox for garden
input_module5 = gr.Checkbox(label="Has Garage")  # Checkbox for garage

# Define output components
output_module1 = gr.Textbox(label="Predicted Price")  # Textbox for predicted price
output_module2 = gr.Textbox(label="Prediction Explanation")  # Textbox for explanation

# Function for housing price prediction (simulate with random values)
def predict_price(square_footage, num_bedrooms, location, has_garden, has_garage):
    price = square_footage * 200 + num_bedrooms * 50000  # Simplified formula
    if location == "Urban":
        price *= 1.5
    if has_garden:
        price += 20000
    if has_garage:
        price += 15000

    explanation = f"Based on {square_footage} sqft, {num_bedrooms} bedrooms, location {location}, garden: {has_garden}, garage: {has_garage}, the predicted price is ${price:.2f}."
    
    return f"${price:.2f}", explanation

# Launch the Gradio interface for housing price prediction
gr.Interface(fn=predict_price, 
             inputs=[input_module1, input_module2, input_module3,
                     input_module4, input_module5], 
             outputs=[output_module1, output_module2]).launch()