crabbly commited on
Commit
7055890
·
1 Parent(s): 53bccd2

Update routing

Browse files
Files changed (1) hide show
  1. main.py +30 -0
main.py CHANGED
@@ -97,6 +97,36 @@ async def proxy_status(username: str = Query("")):
97
  return {"active_requests": 0, "max_concurrent": 2}
98
 
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  @app.post("/proxy_process")
101
  async def proxy_process(request: Request, file: UploadFile = File(...), password: str = Form(""), username: str = Form("")):
102
  base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
 
97
  return {"active_requests": 0, "max_concurrent": 2}
98
 
99
 
100
+ @app.post("/proxy_warmup")
101
+ async def proxy_warmup(payload: dict = Body(...)):
102
+ """Warm the production backend only.
103
+
104
+ This deliberately does not route devtest to the dev Space; it exists to
105
+ keep the production user path responsive without burning analysis jobs.
106
+ """
107
+ target_url = f"{PROD_URL}/warmup"
108
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
109
+
110
+ def make_post():
111
+ return request_with_hf_backoff(
112
+ requests.post,
113
+ target_url,
114
+ max_retries=0,
115
+ headers=headers,
116
+ json=payload,
117
+ timeout=PROCESS_PROXY_TIMEOUT_SECONDS,
118
+ )
119
+
120
+ try:
121
+ response = await run_in_threadpool(make_post)
122
+ response.raise_for_status()
123
+ return response.json()
124
+ except requests.exceptions.RequestException as e:
125
+ return proxy_error_payload("Proxy Warmup Error (Hugging Face)", e)
126
+ except Exception as e:
127
+ return {"success": False, "message": f"Proxy Warmup Error (Internal): {str(e)}"}
128
+
129
+
130
  @app.post("/proxy_process")
131
  async def proxy_process(request: Request, file: UploadFile = File(...), password: str = Form(""), username: str = Form("")):
132
  base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL