-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/SK-1081 | Use stores in Combiner + ModelPredict (#718)
- Loading branch information
Showing
27 changed files
with
579 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from fedn.network.api.v1.client_routes import bp as client_bp | ||
from fedn.network.api.v1.combiner_routes import bp as combiner_bp | ||
from fedn.network.api.v1.helper_routes import bp as helper_bp | ||
from fedn.network.api.v1.inference_routes import bp as inference_bp | ||
from fedn.network.api.v1.model_routes import bp as model_bp | ||
from fedn.network.api.v1.package_routes import bp as package_bp | ||
from fedn.network.api.v1.prediction_routes import bp as prediction_bp | ||
from fedn.network.api.v1.round_routes import bp as round_bp | ||
from fedn.network.api.v1.session_routes import bp as session_bp | ||
from fedn.network.api.v1.status_routes import bp as status_bp | ||
from fedn.network.api.v1.validation_routes import bp as validation_bp | ||
|
||
_routes = [client_bp, combiner_bp, model_bp, package_bp, round_bp, session_bp, status_bp, validation_bp, inference_bp, helper_bp] | ||
_routes = [client_bp, combiner_bp, model_bp, package_bp, round_bp, session_bp, status_bp, validation_bp, prediction_bp, helper_bp] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import threading | ||
|
||
from flask import Blueprint, jsonify, request | ||
|
||
from fedn.network.api.auth import jwt_auth_required | ||
from fedn.network.api.shared import control | ||
from fedn.network.api.v1.shared import api_version, mdb | ||
from fedn.network.storage.statestore.stores.model_store import ModelStore | ||
from fedn.network.storage.statestore.stores.prediction_store import PredictionStore | ||
from fedn.network.storage.statestore.stores.shared import EntityNotFound | ||
|
||
bp = Blueprint("prediction", __name__, url_prefix=f"/api/{api_version}/predict") | ||
|
||
prediction_store = PredictionStore(mdb, "control.predictions") | ||
model_store = ModelStore(mdb, "control.model") | ||
|
||
|
||
@bp.route("/start", methods=["POST"]) | ||
@jwt_auth_required(role="admin") | ||
def start_session(): | ||
"""Start a new prediction session. | ||
param: prediction_id: The session id to start. | ||
type: prediction_id: str | ||
param: rounds: The number of rounds to run. | ||
type: rounds: int | ||
""" | ||
try: | ||
data = request.json if request.headers["Content-Type"] == "application/json" else request.form.to_dict() | ||
prediction_id: str = data.get("prediction_id") | ||
|
||
if not prediction_id or prediction_id == "": | ||
return jsonify({"message": "prediction_id is required"}), 400 | ||
|
||
if data.get("model_id") is None: | ||
count = model_store.count() | ||
if count == 0: | ||
return jsonify({"message": "No models available"}), 400 | ||
else: | ||
try: | ||
model_id = data.get("model_id") | ||
_ = model_store.get(model_id) | ||
except EntityNotFound: | ||
return jsonify({"message": f"Model {model_id} not found"}), 404 | ||
|
||
session_config = {"prediction_id": prediction_id} | ||
|
||
threading.Thread(target=control.prediction_session, kwargs={"config": session_config}).start() | ||
|
||
return jsonify({"message": "Prediction session started"}), 200 | ||
except Exception: | ||
return jsonify({"message": "Failed to start prediction session"}), 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.