initial commit
This commit is contained in:
parent
59b008d8f8
commit
ca7b2e3315
BIN
backend/.DS_Store
vendored
Normal file
BIN
backend/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
backend/app/.DS_Store
vendored
Normal file
BIN
backend/app/.DS_Store
vendored
Normal file
Binary file not shown.
10
backend/app/core/config.py
Normal file
10
backend/app/core/config.py
Normal file
@ -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()
|
||||||
21
backend/app/main.py
Normal file
21
backend/app/main.py
Normal file
@ -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")
|
||||||
21
backend/app/models/prediction.py
Normal file
21
backend/app/models/prediction.py
Normal file
@ -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]
|
||||||
27
backend/app/routers/predictions.py
Normal file
27
backend/app/routers/predictions.py
Normal file
@ -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))
|
||||||
35
backend/app/services/ml_model.py
Normal file
35
backend/app/services/ml_model.py
Normal file
@ -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
|
||||||
3
backend/requirements.txt
Normal file
3
backend/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fastapi
|
||||||
|
pydantic
|
||||||
|
uvicorn
|
||||||
Loading…
x
Reference in New Issue
Block a user