This paste expires on 2023-04-12 11:07:06.027777. Repaste, or download this paste. . Pasted through web.

"""
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):
Filename: None. Size: 2kb. View raw, , hex, or download this file.
INFO:     Started server process [5584]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:64775 - "POST /files/run/?threshold=1.4 HTTP/1.1" 422 Unprocessable Entity
Filename: None. Size: 293b. View raw, , hex, or download this file.