Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import uvicorn
|
| 4 |
from fastapi import FastAPI, Request
|
|
@@ -7,9 +8,13 @@ import time # For precise timestamps
|
|
| 7 |
import asyncio
|
| 8 |
from starlette.middleware.base import BaseHTTPMiddleware
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
limiter = anyio.to_thread.current_default_thread_limiter()
|
| 12 |
limiter.total_tokens = 1000
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# --- 1. DEFINING THE THROTTLING MIDDLEWARE ---
|
| 15 |
class VideoThrottlingMiddleware(BaseHTTPMiddleware):
|
|
@@ -46,10 +51,6 @@ class VideoThrottlingMiddleware(BaseHTTPMiddleware):
|
|
| 46 |
|
| 47 |
app = FastAPI()
|
| 48 |
|
| 49 |
-
@app.on_event("startup")
|
| 50 |
-
async def startup_event():
|
| 51 |
-
await set_max_threads()
|
| 52 |
-
|
| 53 |
# --- 2. ACTIVATING THE MIDDLEWARE ---
|
| 54 |
app.add_middleware(VideoThrottlingMiddleware, max_concurrent_streams=40) # allow max_concurrent_streams from 15 to 50 or 60
|
| 55 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import asyncio
|
| 3 |
import gradio as gr
|
| 4 |
import uvicorn
|
| 5 |
from fastapi import FastAPI, Request
|
|
|
|
| 8 |
import asyncio
|
| 9 |
from starlette.middleware.base import BaseHTTPMiddleware
|
| 10 |
|
| 11 |
+
@asynccontextmanager
|
| 12 |
+
async def lifespan(app: FastAPI):
|
| 13 |
+
# This runs right when the server boots up
|
| 14 |
limiter = anyio.to_thread.current_default_thread_limiter()
|
| 15 |
limiter.total_tokens = 1000
|
| 16 |
+
print("🚀 SUCCESS: Boosted backend worker thread pool capacity to 1000 tokens.")
|
| 17 |
+
yield
|
| 18 |
|
| 19 |
# --- 1. DEFINING THE THROTTLING MIDDLEWARE ---
|
| 20 |
class VideoThrottlingMiddleware(BaseHTTPMiddleware):
|
|
|
|
| 51 |
|
| 52 |
app = FastAPI()
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# --- 2. ACTIVATING THE MIDDLEWARE ---
|
| 55 |
app.add_middleware(VideoThrottlingMiddleware, max_concurrent_streams=40) # allow max_concurrent_streams from 15 to 50 or 60
|
| 56 |
|