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 52cb808 commit c1333ec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from fastapi import FastAPI, UploadFile, File
from PIL import Image
import torch
from torchvision import transforms
from fastapi import FastAPI, File, UploadFile
from main import Net # Importing Net class from main.py
from main import Trainer # Importing Trainer class from main.py
from PIL import Image
from torchvision import transforms

# Load the model
model = Net()
model.load_state_dict(torch.load("mnist_model.pth"))
model.eval()
trainer = Trainer()
trainer.load_model("mnist_model.pth") # Assuming load_model method exists

# Transform used for preprocessing the image
transform = transforms.Compose([
Expand All @@ -23,6 +23,6 @@ async def predict(file: UploadFile = File(...)):
image = transform(image)
image = image.unsqueeze(0) # Add batch dimension
with torch.no_grad():
output = model(image)
output = trainer.get_model()(image) # Assuming get_model method exists
_, predicted = torch.max(output.data, 1)
return {"prediction": int(predicted[0])}

0 comments on commit c1333ec

Please sign in to comment.