Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from robmarkcole/ISSUE34
Browse files Browse the repository at this point in the history
fix issue 34
  • Loading branch information
robmarkcole authored Dec 13, 2022
2 parents e3e3eaa + 03a439e commit b889bb3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
venv/
.vscode
*.pt
#*.jpg
static/tmp.jpg
*.pyc
static/*.png
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<p align="center">
<img src="docs/app_form.jpg" width="450">
Expand All @@ -16,6 +16,8 @@ then visit http://localhost:5000/ in your browser:
<img src="docs/app_result.jpg" width="450">
</p>

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:

Expand Down
Binary file removed static/image0.jpg
Binary file not shown.
9 changes: 7 additions & 2 deletions webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")

Expand Down

0 comments on commit b889bb3

Please sign in to comment.