Skip to content

Commit

Permalink
Adding new/updated cellcanvas_server_0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
kephale committed Aug 13, 2024
1 parent 7da5a77 commit f685f75
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
Binary file modified album_catalog_index.db
Binary file not shown.
3 changes: 3 additions & 0 deletions solutions/cellcanvas/server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 50 additions & 2 deletions solutions/cellcanvas/server/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def run():
import json
import getpass
from contextlib import redirect_stdout, redirect_stderr
import os

args = get_args()

Expand All @@ -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:
Expand Down Expand Up @@ -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(),
Expand All @@ -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():
Expand Down Expand Up @@ -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"],
Expand All @@ -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={
Expand Down
12 changes: 9 additions & 3 deletions solutions/cellcanvas/server/solution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f685f75

Please sign in to comment.