Update tagger_ui_server.py
Browse files- tagger_ui_server.py +40 -0
tagger_ui_server.py
CHANGED
|
@@ -113,6 +113,46 @@ async def tag_upload(
|
|
| 113 |
return _run_tagger(img, max_size, floor)
|
| 114 |
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
# ---------------------------------------------------------------------------
|
| 117 |
# Inference helper
|
| 118 |
# ---------------------------------------------------------------------------
|
|
|
|
| 113 |
return _run_tagger(img, max_size, floor)
|
| 114 |
|
| 115 |
|
| 116 |
+
# ---------------------------------------------------------------------------
|
| 117 |
+
# PCA endpoints
|
| 118 |
+
# ---------------------------------------------------------------------------
|
| 119 |
+
|
| 120 |
+
@app.post("/pca/url")
|
| 121 |
+
async def pca_url(
|
| 122 |
+
url: str = Query(...),
|
| 123 |
+
max_size: int = Query(default=1024),
|
| 124 |
+
):
|
| 125 |
+
from fastapi.responses import Response
|
| 126 |
+
assert _tagger is not None
|
| 127 |
+
try:
|
| 128 |
+
from inference_tagger_standalone import _open_image
|
| 129 |
+
img = _open_image(url)
|
| 130 |
+
except Exception as e:
|
| 131 |
+
raise HTTPException(status_code=400, detail=f"Could not fetch image: {e}")
|
| 132 |
+
pca_img = _tagger.embed_pca(img, max_size=max_size)
|
| 133 |
+
buf = io.BytesIO()
|
| 134 |
+
pca_img.save(buf, format="PNG")
|
| 135 |
+
return Response(content=buf.getvalue(), media_type="image/png")
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
@app.post("/pca/upload")
|
| 139 |
+
async def pca_upload(
|
| 140 |
+
file: UploadFile = File(...),
|
| 141 |
+
max_size: int = Query(default=1024),
|
| 142 |
+
):
|
| 143 |
+
from fastapi.responses import Response
|
| 144 |
+
assert _tagger is not None
|
| 145 |
+
try:
|
| 146 |
+
data = await file.read()
|
| 147 |
+
img = Image.open(io.BytesIO(data)).convert("RGB")
|
| 148 |
+
except Exception as e:
|
| 149 |
+
raise HTTPException(status_code=400, detail=f"Could not read image: {e}")
|
| 150 |
+
pca_img = _tagger.embed_pca(img, max_size=max_size)
|
| 151 |
+
buf = io.BytesIO()
|
| 152 |
+
pca_img.save(buf, format="PNG")
|
| 153 |
+
return Response(content=buf.getvalue(), media_type="image/png")
|
| 154 |
+
|
| 155 |
+
|
| 156 |
# ---------------------------------------------------------------------------
|
| 157 |
# Inference helper
|
| 158 |
# ---------------------------------------------------------------------------
|