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 a5c505d commit b4aaeee
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 cnn import CNN # Importing CNN class from cnn.py
from fastapi import FastAPI, File, UploadFile
from PIL import Image
from torchvision import transforms

from cnn import CNN # Importing CNN class from cnn.py

# Load the model
model = CNN()
model.load_state_dict(torch.load("mnist_model.pth"))
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 b4aaeee

Please sign in to comment.