37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from fastapi import FastAPI
|
|
|
|
from backend.routes.ml import init_ml_routes
|
|
from app.ml.registry.model_registry import ModelRegistry
|
|
from app.ml.training import TrainingPipeline
|
|
from app.ml.feature_store import FeatureStore, FeatureVector
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
application = FastAPI(title="SillyHome Next ML")
|
|
init_ml_routes(application)
|
|
_seed_default_model(application.state if hasattr(application, "state") else application)
|
|
return application
|
|
|
|
|
|
def _app_state(): # noqa: ANN001
|
|
return app.state
|
|
|
|
|
|
def _seed_default_model(state) -> None: # noqa: ANN001
|
|
registry = getattr(state, "registry", None)
|
|
if registry is None:
|
|
registry = ModelRegistry(".model_store")
|
|
state.registry = registry
|
|
|
|
if list(registry.list_models()):
|
|
return
|
|
|
|
store = FeatureStore()
|
|
store.add(FeatureVector(sensor_id="sensor.front_door", values={"contact": 1.0}))
|
|
store.add(FeatureVector(sensor_id="sensor.living_room", values={"temperature": 21.0}))
|
|
pipeline = TrainingPipeline(store)
|
|
artifact = pipeline.run("default")
|
|
registry.register(artifact)
|
|
|
|
|
|
app = create_app() |