kphfrepo commited on
Commit
e66d4f0
·
verified ·
1 Parent(s): 479f746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -1,12 +1,16 @@
1
  import os
2
  import gradio as gr
3
  import uvicorn
4
- from fastapi import FastAPI
5
  from fastapi.staticfiles import StaticFiles
6
  import time # For precise timestamps
7
  import asyncio
8
  from starlette.middleware.base import BaseHTTPMiddleware
9
 
 
 
 
 
10
  # --- 1. DEFINING THE THROTTLING MIDDLEWARE ---
11
  class VideoThrottlingMiddleware(BaseHTTPMiddleware):
12
  def __init__(self, app, max_concurrent_streams: int = 40):
@@ -42,6 +46,10 @@ class VideoThrottlingMiddleware(BaseHTTPMiddleware):
42
 
43
  app = FastAPI()
44
 
 
 
 
 
45
  # --- 2. ACTIVATING THE MIDDLEWARE ---
46
  app.add_middleware(VideoThrottlingMiddleware, max_concurrent_streams=40) # allow max_concurrent_streams from 15 to 50 or 60
47
 
 
1
  import os
2
  import gradio as gr
3
  import uvicorn
4
+ from fastapi import FastAPI, Request
5
  from fastapi.staticfiles import StaticFiles
6
  import time # For precise timestamps
7
  import asyncio
8
  from starlette.middleware.base import BaseHTTPMiddleware
9
 
10
+ async def set_max_threads():
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):
16
  def __init__(self, app, max_concurrent_streams: int = 40):
 
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