Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.linear_model import LinearRegression
|
| 5 |
+
|
| 6 |
+
# Load dataset (online use kar rahe hain taake HF pe chale)
|
| 7 |
+
url = "https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv"
|
| 8 |
+
df = pd.read_csv(url)
|
| 9 |
+
|
| 10 |
+
# Select features
|
| 11 |
+
df = df[['total_rooms', 'households', 'population', 'total_bedrooms']].dropna()
|
| 12 |
+
|
| 13 |
+
# Split data
|
| 14 |
+
X = df[['total_rooms', 'households', 'population']]
|
| 15 |
+
y = df['total_bedrooms']
|
| 16 |
+
|
| 17 |
+
# Train model
|
| 18 |
+
model = LinearRegression()
|
| 19 |
+
model.fit(X, y)
|
| 20 |
+
|
| 21 |
+
# Prediction function
|
| 22 |
+
def predict(total_rooms, households, population):
|
| 23 |
+
data = np.array([[total_rooms, households, population]])
|
| 24 |
+
prediction = model.predict(data)[0]
|
| 25 |
+
return float(prediction)
|
| 26 |
+
|
| 27 |
+
# Gradio UI
|
| 28 |
+
interface = gr.Interface(
|
| 29 |
+
fn=predict,
|
| 30 |
+
inputs=[
|
| 31 |
+
gr.Number(label="Total Rooms"),
|
| 32 |
+
gr.Number(label="Households"),
|
| 33 |
+
gr.Number(label="Population")
|
| 34 |
+
],
|
| 35 |
+
outputs=gr.Number(label="Predicted Bedrooms"),
|
| 36 |
+
title="Housing Bedrooms Prediction",
|
| 37 |
+
description="Predict total bedrooms using linear regression"
|
| 38 |
+
)
|