From 7cf31a863bab21eb403f4d15ce467e4cd8ecf888 Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:30:19 +0000 Subject: [PATCH] Sandbox run src/api.py --- src/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api.py b/src/api.py index b094b12..3804def 100644 --- a/src/api.py +++ b/src/api.py @@ -1,22 +1,23 @@ import torch from fastapi import FastAPI, File, UploadFile -from main import Trainer # Importing Net class from main.py from PIL import Image from torchvision import transforms +from main import Trainer # Importing Net class from main.py + # Load the model trainer = Trainer() model = trainer.model model.eval() # Transform used for preprocessing the image -transform = transforms.Compose([ - transforms.ToTensor(), - transforms.Normalize((0.5,), (0.5,)) -]) +transform = transforms.Compose( + [transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))] +) app = FastAPI() + @app.post("/predict/") async def predict(file: UploadFile = File(...)): image = Image.open(file.file).convert("L")