autotag: accept files from stdin with '-'.

Fix `autotag` so you can pass a filename of '-' to read a file from
stdin. This way you can do this:

  docker run --rm -i ghcr.io/danbooru/autotagger autotag - < image.jpg

...to perform prediction on a single file outside of Docker.
This commit is contained in:
evazion
2022-06-22 15:21:30 -05:00
parent e4344ab2d4
commit 96b6a12924
3 changed files with 11 additions and 11 deletions
+1 -3
View File
@@ -5,7 +5,6 @@ from dotenv import load_dotenv
from autotagger import Autotagger
from base64 import b64encode
from flask import Flask, request, render_template, jsonify
from fastai.vision.core import PILImage
load_dotenv()
model_path = getenv("MODEL_PATH", "models/model.pth")
@@ -22,12 +21,11 @@ def index():
@app.route("/evaluate", methods=["POST"])
def evaluate():
files = request.files.getlist("file")
images = [PILImage.create(file) for file in files]
threshold = float(request.form.get("threshold", 0.1))
output = request.form.get("format", "html")
limit = int(request.form.get("limit", 50))
predictions = autotagger.predict(images, threshold=threshold, limit=limit)
predictions = autotagger.predict(files, threshold=threshold, limit=limit)
if output == "html":
for file in files: