Skip to content

Commit

Permalink
Sandbox run src/api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-nightly[bot] authored Nov 25, 2023
1 parent 7700842 commit 7cf31a8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 7cf31a8

Please sign in to comment.