/
backend.py
41 lines (32 loc) · 1.35 KB
/
backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from sanic import Sanic
from sanic.response import text
from sanic_ext import render
from app import process_pictures
import contextlib
import io
APP_NAME = "Process_Pictures"
app = Sanic(APP_NAME)
app.static('/static', './static')
def invoke_method(request_form):
### --- the below should be generated by codex --- ###
picture_folder_path_str = request_form["picture_folder_path"] if "picture_folder_path" in request_form else None
days_back_int = request_form["days_back"]
process_faces_bool = request_form['process_faces'][0] == 'true' if 'process_faces' in request_form else False
stdout = io.StringIO ()
with contextlib.redirect_stdout(stdout):
value = process_pictures(picture_folder_path_str, days_back_int, process_faces_bool)
return (value, stdout.getvalue())
### --- the above should be generated by codex --- ###
@app.get("/")
@app.ext.template("ui.html")
async def index(request):
context={ "app_name": APP_NAME, "result": None }
return await render(context=context)
@app.post("/")
@app.ext.template("ui.html")
async def process_data(request):
result, stdout = invoke_method(request.form)
context={ "app_name": APP_NAME, "result": result, "request_form": request.form, "stdout": stdout }
return await render(context=context)
if __name__ == "__main__":
app.run(host="0.0.0.0", dev=True)