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 26, 2023
1 parent c1333ec commit b31fc72
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 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 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

from main import Net # Importing Net class from main.py
from main import Trainer # Importing Trainer class from main.py

# Load the model
trainer = Trainer()
trainer.load_model("mnist_model.pth") # Assuming load_model method exists
trainer.load_model("mnist_model.pth") # Assuming load_model method exists

# 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 b31fc72

Please sign in to comment.