Download extensions/sd-model-organizer/scripts/mo/api.py from dikdimon/ext: direct link, hf CLI and curl.
- Browser
- Download file 832 Bytes
-
https://huggingface.co/dikdimon/ext/resolve/main/extensions/sd-model-organizer/scripts/mo/api.py
- Command line
-
hf download hf://dikdimon/ext/extensions/sd-model-organizer/scripts/mo/api.py
-
curl -L -o api.py https://huggingface.co/dikdimon/ext/resolve/main/extensions/sd-model-organizer/scripts/mo/api.py
832 Bytes
| import os | |
| from fastapi import FastAPI | |
| from scripts.mo.environment import logger, env | |
| def init_extension_api(app: FastAPI): | |
| async def get_display_options(): | |
| return { | |
| 'card_width': env.card_width(), | |
| 'card_height': env.card_height(), | |
| 'theme': env.theme() | |
| } | |
| async def get_thumbnail_file(filename: str = ""): | |
| from starlette.responses import FileResponse | |
| ext = os.path.splitext(filename)[1].lower() | |
| if ext not in (".png", ".jpg", ".jpeg", ".webp"): | |
| raise ValueError(f"File cannot be fetched: {filename}. Only png and jpg and jpeg and webp.") | |
| return FileResponse(filename, headers={"Accept-Ranges": "bytes"}) | |
| logger.debug('Model Organizer API initialized') | |