Spaces:
Running

remsky commited on
Commit
8fbdd70
·
unverified ·
1 Parent(s): 071c2c6

feat: add cache control for web responses and update environment variables for future deploy

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -0
  2. hf_app.py +5 -1
Dockerfile CHANGED
@@ -6,6 +6,7 @@ ENV MKL_NUM_THREADS=2
6
 
7
  # Default is DEBUG, which logs every caller's submitted text
8
  ENV API_LOG_LEVEL=INFO
 
9
 
10
  # Root redirect to the bundled web player
11
  COPY hf_app.py /app/hf_app.py
 
6
 
7
  # Default is DEBUG, which logs every caller's submitted text
8
  ENV API_LOG_LEVEL=INFO
9
+ ENV DEFAULT_VOICE=af_jadzia
10
 
11
  # Root redirect to the bundled web player
12
  COPY hf_app.py /app/hf_app.py
hf_app.py CHANGED
@@ -10,6 +10,7 @@ from api.src.main import app
10
 
11
  MAX_BODY_BYTES = int(os.getenv("MAX_BODY_BYTES", 8192))
12
  RATE_LIMIT_PER_MIN = int(os.getenv("RATE_LIMIT_PER_MIN", 20))
 
13
 
14
  _hits: dict[str, deque] = {}
15
 
@@ -22,7 +23,10 @@ def _client_ip(request: Request) -> str:
22
  @app.middleware("http")
23
  async def throttle(request: Request, call_next):
24
  if request.method != "POST":
25
- return await call_next(request)
 
 
 
26
 
27
  length = request.headers.get("content-length")
28
  if length and int(length) > MAX_BODY_BYTES:
 
10
 
11
  MAX_BODY_BYTES = int(os.getenv("MAX_BODY_BYTES", 8192))
12
  RATE_LIMIT_PER_MIN = int(os.getenv("RATE_LIMIT_PER_MIN", 20))
13
+ WEB_CACHE_SECONDS = int(os.getenv("WEB_CACHE_SECONDS", 600))
14
 
15
  _hits: dict[str, deque] = {}
16
 
 
23
  @app.middleware("http")
24
  async def throttle(request: Request, call_next):
25
  if request.method != "POST":
26
+ response = await call_next(request)
27
+ if request.url.path.startswith("/web/") and response.status_code == 200:
28
+ response.headers["Cache-Control"] = f"public, max-age={WEB_CACHE_SECONDS}"
29
+ return response
30
 
31
  length = request.headers.get("content-length")
32
  if length and int(length) > MAX_BODY_BYTES: