|
|
import gradio as gr |
|
|
|
|
|
|
|
|
def predict_price(rooms, area, wall_material): |
|
|
|
|
|
try: |
|
|
rooms = int(rooms) |
|
|
area = float(area) |
|
|
if rooms < 1: |
|
|
return "Error: Number of rooms must be at least 1." |
|
|
if area <= 0: |
|
|
return "Error: Total area must be greater than 0." |
|
|
if wall_material not in ["Brick", "Monolith", "Adobe"]: |
|
|
return "Error: Invalid wall material selected." |
|
|
|
|
|
|
|
|
price = rooms * 1000 + area * 50 |
|
|
return f"Predicted price: ${price:,.2f}" |
|
|
except ValueError: |
|
|
return "Error: Please enter valid numeric values for rooms and area." |
|
|
|
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=predict_price, |
|
|
inputs=[ |
|
|
gr.Number(label="Number of Rooms", value=1, minimum=1, step=1, precision=0), |
|
|
gr.Number(label="Total Area (sq.m)", value=50, minimum=1, precision=2), |
|
|
gr.Dropdown(label="Wall Material", choices=["Brick", "Monolith", "Adobe"], value="Brick") |
|
|
], |
|
|
outputs=gr.Textbox(label="Predicted Price"), |
|
|
title="House Price Prediction", |
|
|
description="Enter the number of rooms, total area, and wall material to predict the house price." |
|
|
) |
|
|
|
|
|
|
|
|
demo.launch() |