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 Oct 23, 2023
1 parent 3da83bc commit 373f92e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fastapi import FastAPI, UploadFile, File
from PIL import Image
import torch
from fastapi import FastAPI, File, UploadFile
from PIL import Image
from torchvision import transforms

from main import MNISTTrainer # Importing MNISTTrainer class from main.py

# Load the model
Expand All @@ -11,13 +12,13 @@
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 373f92e

Please sign in to comment.