| import gradio as gr |
| import numpy as np |
|
|
| |
| input_module1 = gr.Slider(minimum=500, maximum=5000, step=100, label="Square Footage") |
| input_module2 = gr.Slider(minimum=1, maximum=10, step=1, label="Number of Bedrooms") |
| input_module3 = gr.Dropdown(choices=["Urban", "Suburban", "Rural"], label="Location") |
| input_module4 = gr.Checkbox(label="Has Garden") |
| input_module5 = gr.Checkbox(label="Has Garage") |
|
|
| |
| output_module1 = gr.Textbox(label="Predicted Price") |
| output_module2 = gr.Textbox(label="Prediction Explanation") |
|
|
| |
| def predict_price(square_footage, num_bedrooms, location, has_garden, has_garage): |
| price = square_footage * 200 + num_bedrooms * 50000 |
| 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 |
|
|
| |
| gr.Interface(fn=predict_price, |
| inputs=[input_module1, input_module2, input_module3, |
| input_module4, input_module5], |
| outputs=[output_module1, output_module2]).launch() |
|
|