-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fa9864
commit 085a247
Showing
6 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Select the base image | ||
FROM python:3.10 | ||
|
||
# Set the working directory | ||
WORKDIR /code | ||
|
||
# Copy the requirements file | ||
COPY ./requirements.txt /code/requirements.txt | ||
|
||
# Copy the source code | ||
COPY ./api /code/api | ||
COPY ./cifar.h5 /code/cifar.h5 | ||
COPY ./api/ /code/api/ | ||
COPY ./cifar10/ /code/cifar10/ | ||
|
||
|
||
# Install ffmpeg | ||
RUN apt-get update -y | ||
RUN apt-get install ffmpeg libsm6 libxext6 libxext6 -y | ||
|
||
# Install the dependencies | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
|
||
|
||
# Expose the port | ||
EXPOSE 80 | ||
|
||
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "80"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from fastapi import FastAPI | ||
|
||
app = FastAPI( | ||
title="Cifar 10 Api", | ||
description=''' | ||
This is a simple api for cifar 10 dataset. | ||
The classes trainer are the next: | ||
- airplane | ||
- automobile | ||
- bird | ||
- cat | ||
- deer | ||
- dog | ||
- frog | ||
- horse | ||
- ship | ||
- truck | ||
''', | ||
version="1.0", | ||
|
||
) | ||
|
||
from .views import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from . import app | ||
from fastapi import UploadFile, File, HTTPException | ||
import cv2 | ||
from cifar10 import Model | ||
import numpy as np | ||
|
||
model = Model() | ||
|
||
ALLOW_EXTENSION = ['jpg', 'jpeg', 'png', ] | ||
|
||
@app.get('/') | ||
def index(): | ||
return {'message': 'Hello, World!'} | ||
|
||
@app.post('/analyze_image') | ||
async def analyze_image(file: UploadFile = File(...)): | ||
''' | ||
Analyze image and return the result | ||
Args: | ||
file (UploadFile): image file | ||
Returns: | ||
dict: result | ||
''' | ||
extension = file.filename.split('.')[-1].lower() | ||
|
||
if extension not in ALLOW_EXTENSION: | ||
raise HTTPException(status_code=400, detail='File extension not allowed') | ||
|
||
contents = await file.read() | ||
nparr = np.fromstring(contents, np.uint8) | ||
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
|
||
result = model.predict(img) | ||
|
||
return {'predict': result} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,9 @@ opencv-python | |
ipykernel | ||
|
||
#devs | ||
matplotlib | ||
matplotlib | ||
|
||
#api | ||
fastapi | ||
uvicorn | ||
python-multipart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,9 @@ ipykernel | |
|
||
|
||
#dev | ||
matplotlib | ||
matplotlib | ||
|
||
#api | ||
fastapi | ||
uvicorn | ||
python-multipart |