diff --git a/backend/.DS_Store b/backend/.DS_Store new file mode 100644 index 0000000..338d7d9 Binary files /dev/null and b/backend/.DS_Store differ diff --git a/backend/app/.DS_Store b/backend/app/.DS_Store new file mode 100644 index 0000000..0ae1d8d Binary files /dev/null and b/backend/app/.DS_Store differ diff --git a/backend/app/core/config.py b/backend/app/core/config.py new file mode 100644 index 0000000..e3ed20f --- /dev/null +++ b/backend/app/core/config.py @@ -0,0 +1,10 @@ +from pydantic_settings import BaseSettings + +class Settings(BaseSettings): + API_V1_STR: str = "/api/v1" + PROJECT_NAME: str = "House Price Predictor" + + class Config: + case_sensitive = True + +settings = Settings() \ No newline at end of file diff --git a/backend/app/main.py b/backend/app/main.py new file mode 100644 index 0000000..d6becef --- /dev/null +++ b/backend/app/main.py @@ -0,0 +1,21 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from app.routers import predictions + +app = FastAPI( + title="Housing Price Predictor API", + description="API for predicting housing prices", + version="1.0.0" +) + +# Add CORS middleware +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +# Include routers +app.include_router(predictions.router, prefix="/api/v1") \ No newline at end of file diff --git a/backend/app/models/prediction.py b/backend/app/models/prediction.py new file mode 100644 index 0000000..587255c --- /dev/null +++ b/backend/app/models/prediction.py @@ -0,0 +1,21 @@ +from pydantic import BaseModel, Field +from typing import List + +class HousePredictionInput(BaseModel): + square_feet: float = Field(..., gt=0, description="Square footage of the house") + bedrooms: int = Field(..., ge=1, description="Number of bedrooms") + bathrooms: float = Field(..., gt=0, description="Number of bathrooms") + + class Config: + json_schema_extra = { + "example": { + "square_feet": 2000, + "bedrooms": 3, + "bathrooms": 2.5 + } + } + +class HousePredictionOutput(BaseModel): + predicted_price: float + confidence_score: float + similar_listings: List[float] \ No newline at end of file diff --git a/backend/app/routers/predictions.py b/backend/app/routers/predictions.py new file mode 100644 index 0000000..fe869b0 --- /dev/null +++ b/backend/app/routers/predictions.py @@ -0,0 +1,27 @@ +from fastapi import APIRouter, HTTPException +from app.models.prediction import HousePredictionInput, HousePredictionOutput +from app.services.ml_model import HousePricePredictor + +router = APIRouter() +model = HousePricePredictor() + +@router.post("/predict", + response_model=HousePredictionOutput, + summary="Predict house price", + description="Predicts the price of a house based on its features" +) +async def predict_price(input_data: HousePredictionInput) -> HousePredictionOutput: + try: + predicted_price, confidence_score, similar_listings = model.predict( + input_data.square_feet, + input_data.bedrooms, + input_data.bathrooms + ) + + return HousePredictionOutput( + predicted_price=predicted_price, + confidence_score=confidence_score, + similar_listings=similar_listings + ) + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) \ No newline at end of file diff --git a/backend/app/services/ml_model.py b/backend/app/services/ml_model.py new file mode 100644 index 0000000..3a64818 --- /dev/null +++ b/backend/app/services/ml_model.py @@ -0,0 +1,35 @@ +import random +from typing import List, Tuple + +class HousePricePredictor: + """ + Mock ML model that predicts house prices. + In a real scenario, this would load a trained model. + """ + + def __init__(self): + # Mock initialization - in reality would load model weights + pass + + def predict(self, square_feet: float, bedrooms: int, bathrooms: float) -> Tuple[float, float, List[float]]: + """ + Mock prediction method that returns: + - predicted price + - confidence score + - similar listing prices + """ + # Mock prediction logic + base_price = square_feet * 200 + bedroom_value = bedrooms * 25000 + bathroom_value = bathrooms * 15000 + + predicted_price = base_price + bedroom_value + bathroom_value + + # Add some randomness to make it interesting + confidence_score = random.uniform(0.8, 0.99) + similar_listings = [ + predicted_price * random.uniform(0.9, 1.1) + for _ in range(3) + ] + + return predicted_price, confidence_score, similar_listings \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..6f745c3 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,3 @@ +fastapi +pydantic +uvicorn \ No newline at end of file