Skip to content

Commit

Permalink
Plugin: Predict plugin based on YOLO8
Browse files Browse the repository at this point in the history
  • Loading branch information
kvalev committed May 30, 2023
1 parent 399927b commit aa6106c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/workflows/plugins-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ on:
- "ext/**"

jobs:
publish-hello-docker-image:
publish-plugin-docker-images:
strategy:
fail-fast: false
matrix:
plugins:
- realesrgan
- yolo8

runs-on: ubuntu-latest
steps:
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
changed: 'ext/${{ matrix.plugins }}/**'
- name: Checkout
if: steps.changes.outputs.changed == 'true'
uses: actions/checkout@v3

- name: Log in to Docker Hub
if: steps.changes.outputs.changed == 'true'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
if: steps.changes.outputs.changed == 'true'
uses: docker/build-push-action@v2
with:
context: ext/realesrgan
Expand Down
13 changes: 13 additions & 0 deletions ext/yolo8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.10.11-slim-buster

RUN apt-get update && apt-get install -y libgl1 libglib2.0-0

COPY requirements.txt /app/
RUN pip install -r /app/requirements.txt

COPY . /app/
WORKDIR /app

EXPOSE 5000

CMD ["python3", "main.py"]
26 changes: 26 additions & 0 deletions ext/yolo8/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import base64
from flask import Flask, request
from io import BytesIO
from PIL import Image
from ultralytics import YOLO
from ultralytics.yolo.engine.results import Results

app = Flask(__name__)
model = YOLO("yolov8n.pt")

@app.route('/hello', methods=['GET'])
def hello():
return "elloh"

@app.route('/predict', methods=['POST'])
def predict():
image_data = base64.b64decode(request.json['image'])
image = Image.open(BytesIO(image_data))

results: Results = model.predict(image)

return results[0].tojson()

if __name__ == '__main__':
print("running")
app.run(host='0.0.0.0', port=5000)
2 changes: 2 additions & 0 deletions ext/yolo8/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
ultralytics

0 comments on commit aa6106c

Please sign in to comment.