import gradio as gr import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression # Load dataset (online use kar rahe hain taake HF pe chale) url = "https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv" df = pd.read_csv(url) # Select features df = df[['total_rooms', 'households', 'population', 'total_bedrooms']].dropna() # Split data X = df[['total_rooms', 'households', 'population']] y = df['total_bedrooms'] # Train model model = LinearRegression() model.fit(X, y) # Prediction function def predict(total_rooms, households, population): data = np.array([[total_rooms, households, population]]) prediction = model.predict(data)[0] return float(prediction) # Gradio UI interface = gr.Interface( fn=predict, inputs=[ gr.Number(label="Total Rooms"), gr.Number(label="Households"), gr.Number(label="Population") ], outputs=gr.Number(label="Predicted Bedrooms"), title="Housing Bedrooms Prediction", description="Predict total bedrooms using linear regression" )