Skip to content

Commit

Permalink
feat: Updated src/api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-nightly[bot] authored Nov 26, 2023
1 parent d09aad0 commit 6000586
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,11 +1,12 @@
from fastapi import FastAPI, UploadFile, File
from PIL import Image
import torch
from torchvision import transforms
from cnn import CNN
from fastapi import FastAPI, File, UploadFile
from main import Net # Importing Net class from main.py
from PIL import Image
from torchvision import transforms

# Load the model
model = Net()
model = CNN()
model.load_state_dict(torch.load("mnist_model.pth"))
model.eval()

Expand All @@ -25,4 +26,4 @@ async def predict(file: UploadFile = File(...)):
with torch.no_grad():
output = model(image)
_, predicted = torch.max(output.data, 1)
return {"prediction": int(predicted[0])}
return {"prediction": int(predicted[0])}

0 comments on commit 6000586

Please sign in to comment.