import pandas as pd from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split import gradio as gr # ✅ Load inline dataset def load_data(): csv_data = """area,bedrooms,age,price 1000,3,10,500000 1500,4,5,750000 800,2,20,300000 1200,3,15,450000 1600,4,7,800000 """ from io import StringIO return pd.read_csv(StringIO(csv_data)) # ✅ Train model def train_model(): df = load_data() X = df[["area", "bedrooms", "age"]] y = df["price"] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) model = LinearRegression() model.fit(X_train, y_train) return model def predict_price(model, area, bedrooms, age): return model.predict([[area, bedrooms, age]])[0] model = train_model() # ✅ Gradio UI function def gradio_predict(area, bedrooms, age): price = predict_price(model, area, bedrooms, age) return f"🏠 Estimated House Price: ₹{round(price, 2):,.0f}" # ✅ Launch Gradio interface demo = gr.Interface( fn=gradio_predict, inputs=[ gr.Number(label="Area (sq ft)", value=1200), gr.Number(label="Bedrooms", value=3), gr.Number(label="Age of House (years)", value=10) ], outputs="text", title="🏠 House Price Predictor", description="Enter house details to predict price using a trained ML model." ) demo.launch()