alexfremont commited on
Commit
1ef2263
·
1 Parent(s): 7e31555

add logging

Browse files
Files changed (1) hide show
  1. main.py +3 -0
main.py CHANGED
@@ -11,6 +11,7 @@ from steps.preprocess import process_image
11
  from huggingface_hub import hf_hub_download
12
  from architecture.resnet import ResNet
13
  import torch
 
14
 
15
  app = FastAPI()
16
 
@@ -22,8 +23,10 @@ VALID_API_KEYS = os.environ.get("api_key")
22
 
23
  @app.middleware("http")
24
  async def verify_api_key(request, call_next):
 
25
  api_key = request.headers.get("x-api-key")
26
  if api_key is None or api_key not in VALID_API_KEYS:
 
27
  raise HTTPException(status_code=403, detail="Unauthorized")
28
  response = await call_next(request)
29
  return response
 
11
  from huggingface_hub import hf_hub_download
12
  from architecture.resnet import ResNet
13
  import torch
14
+ import logging
15
 
16
  app = FastAPI()
17
 
 
23
 
24
  @app.middleware("http")
25
  async def verify_api_key(request, call_next):
26
+ logging.info(f"Received request: {request.method} {request.url}")
27
  api_key = request.headers.get("x-api-key")
28
  if api_key is None or api_key not in VALID_API_KEYS:
29
+ logging.warning("Unauthorized access attempt.")
30
  raise HTTPException(status_code=403, detail="Unauthorized")
31
  response = await call_next(request)
32
  return response