From f685f75ff5a70f804ec7b5407f6524d792168dd8 Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Tue, 13 Aug 2024 17:00:32 -0400 Subject: [PATCH] Adding new/updated cellcanvas_server_0.0.11 --- album_catalog_index.db | Bin 401408 -> 401408 bytes solutions/cellcanvas/server/CHANGELOG.md | 3 ++ solutions/cellcanvas/server/solution.py | 52 ++++++++++++++++++++++- solutions/cellcanvas/server/solution.yml | 12 ++++-- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/album_catalog_index.db b/album_catalog_index.db index 5d8248eb2d94e4c5046c0c42bdae760038ec384e..da4bd87d47d34356d5a032d6c324bb0601c5c02f 100644 GIT binary patch delta 485 zcmZoTAklC@VuCc|1S4Bwwca8fz_Ld*=Dn# zzzZg!Mz&@K4hCJx##mmC-29Z(oZ{){-ZINf4~Svr3Qfx|QYbFTFUrhIR{%>YZdo(Vv5?X zJcae4G>aQ=GsASdhm88u%{Q<{Gx0V99rd1vldV;Rg@K8a$#Z+pUe*dB=J#wI+u1L$ z-ezQB6K3N8s!?JQpjTC}}V0SjZsEARaz_BR8AAjG>{Cfsu)>frYN2afqS0m4Shk zv7w%cv7w=b<@Dd&Y*wzm;J{Hx%}XiB&&(^)Q79=&OwI<8nR%%x5Z@Q48CaNG8Yda0 zq$VYrnHi@U7@8!d7+G4Rn3yG5CK*|5@8DpoVP_HI_hFbm$AC!%=q3ez4fZKXK=(5; dc?z>nNrbRm*{38xSf=b#;vp=T=_T@PJphVQin0Iz delta 160 zcmZoTAklC@VuCc|qlq%kjE@=1S4DJ~o|w0;~6CL4gux z=E$b{>5a3PqP8nfVSOmg;>z2@Fx~DUqyBXB4Xn{XCBJyK_v~e@5MqAICbyma0_$x? zpr8%QcDZY;&oqVDIXW2l*6^<5Dd1kf70g-1(E*e#;@IB7!B)f0!pC32Fnx{zlMGNW LfPZ?4JX;R{Qbsec diff --git a/solutions/cellcanvas/server/CHANGELOG.md b/solutions/cellcanvas/server/CHANGELOG.md index 259c0f2..ea20fd1 100644 --- a/solutions/cellcanvas/server/CHANGELOG.md +++ b/solutions/cellcanvas/server/CHANGELOG.md @@ -28,6 +28,9 @@ Add endpoint for handling copick configs ## [0.0.2] - 2024-08-10 Fix index for filtered solutions +## [0.0.11] - 2024-08-13 +Models endpoint, track trained models + ## [0.0.10] - 2024-08-13 Add user_id, session_id endpoints. Use remote copick config diff --git a/solutions/cellcanvas/server/solution.py b/solutions/cellcanvas/server/solution.py index 643eefb..9b4cd7a 100644 --- a/solutions/cellcanvas/server/solution.py +++ b/solutions/cellcanvas/server/solution.py @@ -27,6 +27,7 @@ def run(): import json import getpass from contextlib import redirect_stdout, redirect_stderr + import os args = get_args() @@ -52,13 +53,27 @@ def run(): } copick_config_path = args.copick_config_path + models_json_path = args.models_json_path # Get the username of the user running the server current_username = getpass.getuser() + # Dictionary to store information about generated models + generated_models = {} + + # Load existing models from JSON if the file exists + if models_json_path and os.path.exists(models_json_path): + with open(models_json_path, 'r') as f: + generated_models = json.load(f) + class SolutionArgs(BaseModel): args: Optional[Dict[str, Any]] = {} + def save_models_to_json(): + if models_json_path: + with open(models_json_path, 'w') as f: + json.dump(generated_models, f, indent=2) + def check_solution_allowed(catalog: str, group: str, name: str): solution_path = f"{catalog}:{group}:{name}" if solution_path not in allowed_solutions: @@ -92,6 +107,17 @@ def run_solution_endpoint(catalog: str, group: str, name: str, version: str, sol if error_output.getvalue(): print(f"Errors: {error_output.getvalue()}") + # Check if this solution generates a model + output_model_path = next((arg.split('=')[1] for arg in args_list if arg.startswith('--output_model_path=')), None) + if output_model_path: + generated_models[output_model_path] = { + "catalog": catalog, + "group": group, + "name": name, + "version": version + } + save_models_to_json() + return { "result": result, "stdout": output.getvalue(), @@ -107,6 +133,21 @@ def run_solution_endpoint(catalog: str, group: str, name: str, version: str, sol print(f"Error occurred while running solution: {error_trace}") raise HTTPException(status_code=500, detail=f"Internal Server Error: {str(e)}") + @app.get("/models") + def get_models(): + try: + # Filter out models that no longer exist on the filesystem + existing_models = {path: info for path, info in generated_models.items() if os.path.exists(path)} + + # Update the JSON file if any models were removed + if len(existing_models) != len(generated_models): + generated_models.clear() + generated_models.update(existing_models) + save_models_to_json() + + return {"models": existing_models} + except Exception as e: + raise HTTPException(status_code=500, detail=f"Error fetching models: {str(e)}") @app.get("/user_session_ids") def get_user_session_ids(): @@ -278,7 +319,7 @@ def upgrade_endpoint(): setup( group="cellcanvas", name="server", - version="0.0.10", + version="0.0.11", title="FastAPI CellCanvas Server", description="Backend for CellCanvas with Copick Config Support.", solution_creators=["Kyle Harrington"], @@ -291,7 +332,14 @@ def upgrade_endpoint(): "type": "string", "default": "/path/to/copick/config.json", "description": "Path to the Copick configuration file." - } + }, + { + "name": "models_json_path", + "type": "string", + "default": "", + "description": "Path to the JSON file for storing model listings. If not provided, model listings will not be persisted.", + "required": False + } ], run=run, dependencies={ diff --git a/solutions/cellcanvas/server/solution.yml b/solutions/cellcanvas/server/solution.yml index 0430130..115b9ff 100644 --- a/solutions/cellcanvas/server/solution.yml +++ b/solutions/cellcanvas/server/solution.yml @@ -4,7 +4,13 @@ args: description: Path to the Copick configuration file. name: copick_config_path type: string -changelog: Add user_id, session_id endpoints. Use remote copick config +- default: '' + description: Path to the JSON file for storing model listings. If not provided, + model listings will not be persisted. + name: models_json_path + required: false + type: string +changelog: Models endpoint, track trained models description: Backend for CellCanvas with Copick Config Support. group: cellcanvas license: MIT @@ -16,6 +22,6 @@ tags: - album - server - copick -timestamp: '2024-08-13T16:50:19.667895' +timestamp: '2024-08-13T17:00:31.430336' title: FastAPI CellCanvas Server -version: 0.0.10 +version: 0.0.11