| """
|
| Using fastapis to call the core script for producing and
|
|
|
| """
|
| from dataclasses import asdict
|
| from typing import List
|
| from fastapi import FastAPI, HTTPException, Path
|
| from pydantic import BaseModel
|
| import uvicorn
|
| from src.spot_detection import SpotDetection, CountAgenCreationError, ImageFile
|
|
|
|
|
| class Item(BaseModel):
|
| """
|
| Base model for JSON request.
|
| """
|
| name: str
|
| channels: int
|
| z_stack: int
|
| x_dimension: int
|
| y_dimension: int
|
| previewUrl: str
|
|
|
|
|
| app = FastAPI()
|
| spot_detection = SpotDetection(None, None)
|
|
|
| @app.post("/files/run/")
|
| async def run_img_spotter(item: Item, threshold: float = 1.4):
|
| """
|
| Return the image created for the counted number of spots.
|
|
|
| Args:
|
|
|
| item (Item) : Item object containing
|
| - name: str
|
| - channels: int
|
| - z_stack: int
|
| - x_dimension: int
|
| - y_dimension: int
|
| - previewUrl: str
|
|
|
| threshold (float): Value of threshold. Default : 1.4
|
|
|
| Returns:
|
|
|
| dictionary containing image properties and link to generated graphs.
|
| """
|
| spot_detection.threshold = threshold
|
| image_object = ImageFile(name=item.name, channels=item.channels, x_dimension=item.x_dimension,
|
| y_dimension=item.y_dimension, z_stack=item.z_stack, previewUrl=item.previewUrl)
|
| kwargs = {
|
| "output_folder": spot_detection.output_img_dir,
|
| "plot_blob": True
|
| }
|
| try:
|
| *_, prev = spot_detection.spot_caller(image_object, **kwargs)
|
| except Exception as exc:
|
| raise HTTPException(
|
| status_code=500, detail=str(exc)) from exc
|
| return {"items": [{**asdict(image_object), "graphs": prev}]}
|
|
|
|
|
| @app.post("/files/run/all")
|
| async def run_all_spotter(imgs: List[Item],
|
| threshold: float = 1.4):
|