Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,8 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
from sklearn.linear_model import LinearRegression
|
| 5 |
from sklearn.model_selection import train_test_split
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
app = FastAPI()
|
| 9 |
-
|
| 10 |
-
@app.get("/")
|
| 11 |
-
def read_root():
|
| 12 |
-
return {"message": "House Price Prediction API is running"}
|
| 13 |
-
|
| 14 |
# ✅ Load inline dataset
|
| 15 |
def load_data():
|
| 16 |
csv_data = """area,bedrooms,age,price
|
|
@@ -38,22 +30,12 @@ def predict_price(model, area, bedrooms, age):
|
|
| 38 |
|
| 39 |
model = train_model()
|
| 40 |
|
| 41 |
-
# ✅
|
| 42 |
-
class HouseFeatures(BaseModel):
|
| 43 |
-
area: float
|
| 44 |
-
bedrooms: int
|
| 45 |
-
age: int
|
| 46 |
-
|
| 47 |
-
@app.post("/predict")
|
| 48 |
-
def predict(data: HouseFeatures):
|
| 49 |
-
price = predict_price(model, data.area, data.bedrooms, data.age)
|
| 50 |
-
return {"predicted_price": round(price, 2)}
|
| 51 |
-
|
| 52 |
-
# ✅ Gradio UI
|
| 53 |
def gradio_predict(area, bedrooms, age):
|
| 54 |
price = predict_price(model, area, bedrooms, age)
|
| 55 |
return f"Predicted Price: ₹{round(price, 2):,.0f}"
|
| 56 |
|
|
|
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=gradio_predict,
|
| 59 |
inputs=[
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
from sklearn.linear_model import LinearRegression
|
| 3 |
from sklearn.model_selection import train_test_split
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# ✅ Load inline dataset
|
| 7 |
def load_data():
|
| 8 |
csv_data = """area,bedrooms,age,price
|
|
|
|
| 30 |
|
| 31 |
model = train_model()
|
| 32 |
|
| 33 |
+
# ✅ Gradio UI function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def gradio_predict(area, bedrooms, age):
|
| 35 |
price = predict_price(model, area, bedrooms, age)
|
| 36 |
return f"Predicted Price: ₹{round(price, 2):,.0f}"
|
| 37 |
|
| 38 |
+
# ✅ Launch Gradio interface
|
| 39 |
demo = gr.Interface(
|
| 40 |
fn=gradio_predict,
|
| 41 |
inputs=[
|