Spaces:
Sleeping
Sleeping
Gruhit Patel
commited on
added middleware to note time
Browse files
main.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import List, Union
|
|
| 8 |
import numpy as np
|
| 9 |
from arena import get_move_for_bot
|
| 10 |
import torch
|
|
|
|
| 11 |
|
| 12 |
class Request(BaseModel):
|
| 13 |
board: List[List[int]]
|
|
@@ -38,6 +39,15 @@ model = Model(
|
|
| 38 |
model.load_state_dict(torch.load(Config.checkpoint_path))
|
| 39 |
model.eval()
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
@app.get("/")
|
| 42 |
def root():
|
| 43 |
return {"message": "This is a temporary response"}
|
|
|
|
| 8 |
import numpy as np
|
| 9 |
from arena import get_move_for_bot
|
| 10 |
import torch
|
| 11 |
+
import time
|
| 12 |
|
| 13 |
class Request(BaseModel):
|
| 14 |
board: List[List[int]]
|
|
|
|
| 39 |
model.load_state_dict(torch.load(Config.checkpoint_path))
|
| 40 |
model.eval()
|
| 41 |
|
| 42 |
+
# Create a middleware to record time
|
| 43 |
+
@app.middleware("http")
|
| 44 |
+
async def add_process_time_header(req, call_next):
|
| 45 |
+
start_time = time.time()
|
| 46 |
+
response = await call_next(req)
|
| 47 |
+
process_time = time.time() - start_time
|
| 48 |
+
print(f'Time taken for response = {process_time:.2f} seconds')
|
| 49 |
+
return response
|
| 50 |
+
|
| 51 |
@app.get("/")
|
| 52 |
def root():
|
| 53 |
return {"message": "This is a temporary response"}
|