added semaphore for cnn server

This commit is contained in:
2026-04-30 20:08:48 +02:00
parent 4c38140661
commit 476bb1f045
2 changed files with 16 additions and 11 deletions
Binary file not shown.
+5
View File
@@ -11,9 +11,13 @@ import torch.nn.functional as F
from bird_cnn import Bird_CNN
import threading
BUILD_PATH = "./build_models"
IMAGE_SIZE = 256
sem = threading.Semaphore(1) #adjust to performance
class bird_species(Enum):
Common_Kingfisher = 0
CommonMyna = 1
@@ -53,6 +57,7 @@ app.add_middleware(
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
with sem:
image_bytes = await file.read()
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")