Spaces:
Paused
Paused
yutoAb commited on
Commit ·
1996bfd
1
Parent(s): 3b49605
Revert "Enhance proxy functionality and add health check endpoints; update Gradio version in requirements"
Browse filesThis reverts commit 3b496050a7f0e5bad3a87a582755fa196cf676a0.
- app.py +3 -64
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -58,14 +58,6 @@ async def proxy_http_request(request: Request, target_port: int):
|
|
| 58 |
path = path[8:] # Remove "/model1/"
|
| 59 |
elif path.startswith("/model2/"):
|
| 60 |
path = path[8:] # Remove "/model2/"
|
| 61 |
-
elif path == "/model1" or path == "/model2":
|
| 62 |
-
path = ""
|
| 63 |
-
|
| 64 |
-
# Ensure path starts with / or is empty
|
| 65 |
-
if path and not path.startswith("/"):
|
| 66 |
-
path = "/" + path
|
| 67 |
-
elif not path:
|
| 68 |
-
path = "/"
|
| 69 |
|
| 70 |
target_url = f"http://localhost:{target_port}{path}"
|
| 71 |
|
|
@@ -109,14 +101,6 @@ async def proxy_websocket(websocket: WebSocket, target_port: int):
|
|
| 109 |
path = path[8:]
|
| 110 |
elif path.startswith("/model2/"):
|
| 111 |
path = path[8:]
|
| 112 |
-
elif path == "/model1" or path == "/model2":
|
| 113 |
-
path = ""
|
| 114 |
-
|
| 115 |
-
# Ensure path starts with / or is empty
|
| 116 |
-
if path and not path.startswith("/"):
|
| 117 |
-
path = "/" + path
|
| 118 |
-
elif not path:
|
| 119 |
-
path = "/"
|
| 120 |
|
| 121 |
target_url = f"ws://localhost:{target_port}{path}"
|
| 122 |
|
|
@@ -204,9 +188,6 @@ def start_moshi_server(model_repo: str, port: int, model_name: str):
|
|
| 204 |
def create_gradio_interface() -> gr.Blocks:
|
| 205 |
"""Create the Gradio tabbed interface"""
|
| 206 |
|
| 207 |
-
# Get the Space name from environment for proper URL construction
|
| 208 |
-
space_id = os.environ.get("SPACE_ID", "")
|
| 209 |
-
|
| 210 |
with gr.Blocks(
|
| 211 |
title="Dual Moshi Model Interface",
|
| 212 |
theme=gr.themes.Soft(),
|
|
@@ -311,33 +292,7 @@ def main():
|
|
| 311 |
# Add proxy routes to the underlying FastAPI app
|
| 312 |
logger.info("Setting up reverse proxy routes...")
|
| 313 |
|
| 314 |
-
# Health check endpoints
|
| 315 |
-
@demo.app.get("/health")
|
| 316 |
-
async def health_check():
|
| 317 |
-
return {"status": "ok", "message": "Main app is running"}
|
| 318 |
-
|
| 319 |
-
@demo.app.get("/model1/health")
|
| 320 |
-
async def model1_health():
|
| 321 |
-
try:
|
| 322 |
-
response = await http_client.get("http://localhost:8998/")
|
| 323 |
-
return {"status": "ok", "model": "model1", "backend_status": response.status_code}
|
| 324 |
-
except Exception as e:
|
| 325 |
-
return {"status": "error", "model": "model1", "error": str(e)}
|
| 326 |
-
|
| 327 |
-
@demo.app.get("/model2/health")
|
| 328 |
-
async def model2_health():
|
| 329 |
-
try:
|
| 330 |
-
response = await http_client.get("http://localhost:8999/")
|
| 331 |
-
return {"status": "ok", "model": "model2", "backend_status": response.status_code}
|
| 332 |
-
except Exception as e:
|
| 333 |
-
return {"status": "error", "model": "model2", "error": str(e)}
|
| 334 |
-
|
| 335 |
# Proxy routes for model 1 (port 8998)
|
| 336 |
-
# Handle both /model1 and /model1/ and /model1/path
|
| 337 |
-
@demo.app.api_route("/model1", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 338 |
-
async def proxy_model1_root(request: Request):
|
| 339 |
-
return await proxy_http_request(request, 8998)
|
| 340 |
-
|
| 341 |
@demo.app.api_route("/model1/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 342 |
async def proxy_model1_http(request: Request, path: str):
|
| 343 |
return await proxy_http_request(request, 8998)
|
|
@@ -347,10 +302,6 @@ def main():
|
|
| 347 |
await proxy_websocket(websocket, 8998)
|
| 348 |
|
| 349 |
# Proxy routes for model 2 (port 8999)
|
| 350 |
-
@demo.app.api_route("/model2", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 351 |
-
async def proxy_model2_root(request: Request):
|
| 352 |
-
return await proxy_http_request(request, 8999)
|
| 353 |
-
|
| 354 |
@demo.app.api_route("/model2/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 355 |
async def proxy_model2_http(request: Request, path: str):
|
| 356 |
return await proxy_http_request(request, 8999)
|
|
@@ -360,30 +311,18 @@ def main():
|
|
| 360 |
await proxy_websocket(websocket, 8999)
|
| 361 |
|
| 362 |
logger.info("Proxy routes registered:")
|
| 363 |
-
logger.info(" /
|
| 364 |
-
logger.info(" /
|
| 365 |
-
logger.info(" /model2/health -> Model 2 health check")
|
| 366 |
-
logger.info(" /model1, /model1/* -> http://localhost:8998")
|
| 367 |
-
logger.info(" /model2, /model2/* -> http://localhost:8999")
|
| 368 |
|
| 369 |
# Launch on a different port (main interface)
|
| 370 |
main_port = 7860
|
| 371 |
logger.info(f"Launching main interface on port {main_port}...")
|
| 372 |
|
| 373 |
-
# Detect if running in HF Spaces
|
| 374 |
-
is_hf_space = "SPACE_ID" in os.environ
|
| 375 |
-
logger.info(f"Running in HF Spaces: {is_hf_space}")
|
| 376 |
-
if is_hf_space:
|
| 377 |
-
logger.info(f"Space ID: {os.environ.get('SPACE_ID')}")
|
| 378 |
-
|
| 379 |
try:
|
| 380 |
demo.launch(
|
| 381 |
server_name="0.0.0.0",
|
| 382 |
server_port=main_port,
|
| 383 |
-
share=False
|
| 384 |
-
show_api=False,
|
| 385 |
-
# Don't try to auto-detect root path in HF Spaces
|
| 386 |
-
root_path=os.environ.get("GRADIO_ROOT_PATH", None)
|
| 387 |
)
|
| 388 |
except KeyboardInterrupt:
|
| 389 |
logger.info("Shutting down...")
|
|
|
|
| 58 |
path = path[8:] # Remove "/model1/"
|
| 59 |
elif path.startswith("/model2/"):
|
| 60 |
path = path[8:] # Remove "/model2/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
target_url = f"http://localhost:{target_port}{path}"
|
| 63 |
|
|
|
|
| 101 |
path = path[8:]
|
| 102 |
elif path.startswith("/model2/"):
|
| 103 |
path = path[8:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
target_url = f"ws://localhost:{target_port}{path}"
|
| 106 |
|
|
|
|
| 188 |
def create_gradio_interface() -> gr.Blocks:
|
| 189 |
"""Create the Gradio tabbed interface"""
|
| 190 |
|
|
|
|
|
|
|
|
|
|
| 191 |
with gr.Blocks(
|
| 192 |
title="Dual Moshi Model Interface",
|
| 193 |
theme=gr.themes.Soft(),
|
|
|
|
| 292 |
# Add proxy routes to the underlying FastAPI app
|
| 293 |
logger.info("Setting up reverse proxy routes...")
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
# Proxy routes for model 1 (port 8998)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
@demo.app.api_route("/model1/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 297 |
async def proxy_model1_http(request: Request, path: str):
|
| 298 |
return await proxy_http_request(request, 8998)
|
|
|
|
| 302 |
await proxy_websocket(websocket, 8998)
|
| 303 |
|
| 304 |
# Proxy routes for model 2 (port 8999)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
@demo.app.api_route("/model2/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
| 306 |
async def proxy_model2_http(request: Request, path: str):
|
| 307 |
return await proxy_http_request(request, 8999)
|
|
|
|
| 311 |
await proxy_websocket(websocket, 8999)
|
| 312 |
|
| 313 |
logger.info("Proxy routes registered:")
|
| 314 |
+
logger.info(" /model1/* -> http://localhost:8998")
|
| 315 |
+
logger.info(" /model2/* -> http://localhost:8999")
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
# Launch on a different port (main interface)
|
| 318 |
main_port = 7860
|
| 319 |
logger.info(f"Launching main interface on port {main_port}...")
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
try:
|
| 322 |
demo.launch(
|
| 323 |
server_name="0.0.0.0",
|
| 324 |
server_port=main_port,
|
| 325 |
+
share=False
|
|
|
|
|
|
|
|
|
|
| 326 |
)
|
| 327 |
except KeyboardInterrupt:
|
| 328 |
logger.info("Shutting down...")
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
moshi>=0.2.0,<=0.2.2
|
| 2 |
-
gradio>=
|
| 3 |
httpx>=0.27.0
|
| 4 |
websockets>=12.0
|
| 5 |
-
fastapi>=0.104.0
|
|
|
|
| 1 |
moshi>=0.2.0,<=0.2.2
|
| 2 |
+
gradio>=4.0.0
|
| 3 |
httpx>=0.27.0
|
| 4 |
websockets>=12.0
|
|
|