forked from photoprism/photoprism
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: Predict plugin based on YOLO8
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
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
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,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"] |
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,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) |
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,2 @@ | ||
Flask | ||
ultralytics |