Update labeling augmentation
Browse files
main.py
CHANGED
|
@@ -463,5 +463,56 @@ async def proxy_preview_session_clear(payload: dict = Body(...)):
|
|
| 463 |
except Exception as e:
|
| 464 |
return {"success": False, "message": f"Proxy Error: {str(e)}"}
|
| 465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
if __name__ == "__main__":
|
| 467 |
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
|
|
|
|
| 463 |
except Exception as e:
|
| 464 |
return {"success": False, "message": f"Proxy Error: {str(e)}"}
|
| 465 |
|
| 466 |
+
|
| 467 |
+
@app.api_route("/proxy_adjustments{rest:path}", methods=["GET", "POST", "PUT"])
|
| 468 |
+
async def proxy_adjustments(rest: str, request: Request):
|
| 469 |
+
"""Forward preview-mask and traditional-feature adjustment requests."""
|
| 470 |
+
username = request.query_params.get("username", "")
|
| 471 |
+
content_type = request.headers.get("content-type", "")
|
| 472 |
+
files = []
|
| 473 |
+
data = {}
|
| 474 |
+
json_body = None
|
| 475 |
+
if request.method in {"POST", "PUT"}:
|
| 476 |
+
if "multipart/form-data" in content_type:
|
| 477 |
+
form = await request.form()
|
| 478 |
+
for key, value in form.multi_items():
|
| 479 |
+
if hasattr(value, "filename"):
|
| 480 |
+
files.append((key, (value.filename, await value.read(), value.content_type)))
|
| 481 |
+
else:
|
| 482 |
+
data[key] = str(value)
|
| 483 |
+
username = username or data.get("username", "")
|
| 484 |
+
elif "application/json" in content_type:
|
| 485 |
+
json_body = await request.json()
|
| 486 |
+
if isinstance(json_body, dict):
|
| 487 |
+
username = username or str(json_body.get("username", ""))
|
| 488 |
+
base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
|
| 489 |
+
target_url = f"{base_url}/adjustments{rest}"
|
| 490 |
+
if request.url.query:
|
| 491 |
+
target_url += f"?{request.url.query}"
|
| 492 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 493 |
+
|
| 494 |
+
def make_request():
|
| 495 |
+
return request_with_hf_backoff(
|
| 496 |
+
getattr(requests, request.method.lower()),
|
| 497 |
+
target_url,
|
| 498 |
+
max_retries=0,
|
| 499 |
+
headers=headers,
|
| 500 |
+
files=files or None,
|
| 501 |
+
data=data or None,
|
| 502 |
+
json=json_body,
|
| 503 |
+
timeout=DATASET_PROXY_TIMEOUT_SECONDS,
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
+
try:
|
| 507 |
+
response = await run_in_threadpool(make_request)
|
| 508 |
+
return Response(
|
| 509 |
+
content=response.content,
|
| 510 |
+
status_code=response.status_code,
|
| 511 |
+
media_type=response.headers.get("content-type", "application/json"),
|
| 512 |
+
)
|
| 513 |
+
except requests.exceptions.RequestException as exc:
|
| 514 |
+
return JSONResponse(status_code=502, content=proxy_error_payload("Proxy Error (Hugging Face)", exc))
|
| 515 |
+
|
| 516 |
+
|
| 517 |
if __name__ == "__main__":
|
| 518 |
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
|