Download api.py from aakkaasshh/Random-Image-as-a-Service: direct link, hf CLI and curl.
- Browser
- Download file 759 Bytes
-
https://huggingface.co/spaces/aakkaasshh/Random-Image-as-a-Service/resolve/main/api.py
- Command line
-
hf download hf://spaces/aakkaasshh/Random-Image-as-a-Service/api.py
-
curl -L -o api.py https://huggingface.co/spaces/aakkaasshh/Random-Image-as-a-Service/resolve/main/api.py
759 Bytes
| import io | |
| from fastapi import FastAPI, Query, Response, HTTPException | |
| from core import service, config | |
| app = FastAPI(title="RIaaS — Random Image as a Service") | |
| def get_image( | |
| width: int = Query(config.DEFAULT_WIDTH, ge=config.MIN_WIDTH, le=config.MAX_WIDTH), | |
| height: int = Query(config.DEFAULT_HEIGHT, ge=config.MIN_HEIGHT, le=config.MAX_HEIGHT), | |
| style: str = Query(None), | |
| seed: int = Query(None), | |
| ) -> Response: | |
| try: | |
| image, meta = service.generate(width, height, style, seed) | |
| except ValueError as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) | |
| buf = io.BytesIO() | |
| image.save(buf, format="PNG") | |
| buf.seek(0) | |
| return Response(content=buf.read(), media_type="image/png") | |