from fastapi import FastAPI, File, UploadFile, Response, HTTPException from fastapi.responses import HTMLResponse from img_proc import pixelate, img2byte import fileutils as fu app = FastAPI() @app.get("/", response_class=HTMLResponse, include_in_schema=False) async def root_html(): return """ pixelate via API

pixelate

go to /docs for OpenAPI docs

based on: https://github.com/ferretj/pixelate

""" @app.post("/") async def root(saturation: float = 1.5, contrast: float = 1.2, n_colors: int = 10, superpixel_size: int = 15, file: UploadFile = File(...)): """ saturation: float = 1.25, contrast: float = 1.2, n_colors: int = 10, superpixel_size: int = 10, """ if not fu.has_valid_suffix(file.filename): raise HTTPException(status_code=400, detail="Invalid file ending! Only {} accepted".fomrat(fs.VALID_FILE_FORMATS)) out_img = pixelate(file.file, saturation = saturation, contrast = contrast, n_colors = n_colors, superpixel_size = superpixel_size) return Response(content=img2byte(out_img), media_type="image/png")