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 24, 2023
1 parent 913547b commit c758ee7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""
This script creates a FastAPI application for making predictions using the PyTorch model defined in main.py.
"""
# torch is the main PyTorch library
import torch

# FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
from fastapi import FastAPI, UploadFile, File
from fastapi import FastAPI, File, UploadFile

# PIL is used for opening, manipulating, and saving many different image file formats
from PIL import Image
# torch is the main PyTorch library
import torch

# torchvision.transforms provides classes for transforming images
from torchvision import transforms

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

Expand All @@ -18,14 +22,14 @@
model.eval()

# Define a sequence of preprocessing steps to be applied to the input images
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))
])
transform = transforms.Compose(
[transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))]
)

# Create an instance of the FastAPI application
app = FastAPI()


# Define a route handler for making predictions using the model
@app.post("/predict/")
async def predict(file: UploadFile = File(...)):
Expand Down

0 comments on commit c758ee7

Please sign in to comment.