diff --git a/.gitignore b/.gitignore index 02c73d6..d5a524f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ venv/ .vscode *.pt -#*.jpg -static/tmp.jpg *.pyc +static/*.png diff --git a/README.md b/README.md index 8cc104b..5fb1f16 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Simple app consisting of a form where you can upload an image, and see the infer `$ python3 webapp.py --port 5000` -then visit http://localhost:5000/ in your browser: +then visit [http://localhost:5000/](http://localhost:5000/) in your browser:

@@ -16,6 +16,8 @@ then visit http://localhost:5000/ in your browser:

+Processed images are saved in the `static` directory with a datetime for the filename. + ## Rest API Simple rest API exposing the model for consumption by another service. Run: diff --git a/static/image0.jpg b/static/image0.jpg deleted file mode 100644 index 4be70c7..0000000 Binary files a/static/image0.jpg and /dev/null differ diff --git a/webapp.py b/webapp.py index 7b25591..1649912 100644 --- a/webapp.py +++ b/webapp.py @@ -6,12 +6,15 @@ import io import os from PIL import Image +import datetime import torch from flask import Flask, render_template, request, redirect app = Flask(__name__) +DATETIME_FORMAT = "%Y-%m-%d_%H-%M-%S-%f" + @app.route("/", methods=["GET", "POST"]) def predict(): @@ -27,8 +30,10 @@ def predict(): results = model([img]) results.render() # updates results.imgs with boxes and labels - results.save(save_dir="static/") - return redirect("static/image0.jpg") + now_time = datetime.datetime.now().strftime(DATETIME_FORMAT) + img_savename = f"static/{now_time}.png" + Image.fromarray(results.ims[0]).save(img_savename) + return redirect(img_savename) return render_template("index.html")