From c6817a2de1dabb89082235839942e7dc6cb73090 Mon Sep 17 00:00:00 2001 From: Iskandar Setiadi Date: Sat, 18 Nov 2017 16:34:57 +0000 Subject: [PATCH] Simple uploader --- README.md | 17 +++++++++++++++++ setup.py | 9 +++++++++ src/moeflow/cmds/main.py | 25 +++++++++++++++++++++++-- src/moeflow/jinja2_env.py | 13 +++++++++++++ src/moeflow/static/main.css | 0 src/moeflow/templates/main.html | 19 +++++++++++++++++++ tests/test_example.py | 6 +++--- 7 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 src/moeflow/jinja2_env.py create mode 100644 src/moeflow/static/main.css create mode 100644 src/moeflow/templates/main.html diff --git a/README.md b/README.md index 3da1099..64c67cf 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,23 @@ Repository for anime characters recognition website, powered by TensorFlow - TensorFlow 1.4.0 (`pip install tensorflow==1.4.0` first) +## How to run + +For first-timers: + +``` +$ virtualenv -p python3 venv # Ensure python3 version is 3.5, otherwise TensorFlow might not work +$ . venv/bin/activate + +``` + +After that, you can simply run it by: + +``` +$ pip install -e . +$ app +``` + ## License This project itself is licensed under MIT License. diff --git a/setup.py b/setup.py index 4ba762a..598b48f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,16 @@ from setuptools import find_packages, setup requires = [ + 'aiofiles==0.3.2', 'attrs==17.3.0', + 'httptools==0.0.9', + 'jinja2==2.10', + 'MarkupSafe==1.0', + 'python-magic==0.4.13', + 'sanic==0.6.0', + 'ujson==1.35', + 'uvloop==0.8.1', + 'websockets==4.0.1', ] console_scripts = [ diff --git a/src/moeflow/cmds/main.py b/src/moeflow/cmds/main.py index 1603616..d6594f1 100644 --- a/src/moeflow/cmds/main.py +++ b/src/moeflow/cmds/main.py @@ -1,7 +1,28 @@ # -*- coding: utf-8 -*- -def main(): - print("Hello MoeFlow!") +import jinja2 +import logging +import os +from sanic import Sanic, response +from moeflow.jinja2_env import render + +app = Sanic(__name__) +dir_path = os.path.dirname(os.path.realpath(__file__)) +app.static('/static', os.path.join(dir_path, '..', 'static')) + + +@app.route("/", methods=['GET', 'POST']) +async def hello_world(request): + if request.method == "POST": + uploaded_image = request.files.get('uploaded_image') + logging.info(uploaded_image.name) + return response.html(render("main.html")) +def main(): + # Set logger + logging.basicConfig(level=logging.INFO) + app.run(host="0.0.0.0", port=8888) + if __name__ == '__main__': main() + diff --git a/src/moeflow/jinja2_env.py b/src/moeflow/jinja2_env.py new file mode 100644 index 0000000..51532a8 --- /dev/null +++ b/src/moeflow/jinja2_env.py @@ -0,0 +1,13 @@ +import os + +import jinja2 + +dir_path = os.path.dirname(os.path.realpath(__file__)) + + +def render(tpl_path, context={}): + return jinja2.Environment( + loader=jinja2.FileSystemLoader( + os.path.join(dir_path, 'templates') + ) + ).get_template(tpl_path).render(context) diff --git a/src/moeflow/static/main.css b/src/moeflow/static/main.css new file mode 100644 index 0000000..e69de29 diff --git a/src/moeflow/templates/main.html b/src/moeflow/templates/main.html new file mode 100644 index 0000000..c5d89f4 --- /dev/null +++ b/src/moeflow/templates/main.html @@ -0,0 +1,19 @@ + + + + MoeFlow: Anime Characters Recognition + + + +

MoeFlow: Anime Characters Recognition (Alpha Ver.)

+

For more information, see freedomofkeima/transfer-learning-anime at Github.

+
+ + +
+ + + + diff --git a/tests/test_example.py b/tests/test_example.py index ae9b624..abd03ba 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from moeflow.cmds.main import main +from moeflow.cmds.main import hello_world -def test_main(): - main() +def test_hello_world(): + hello_world(object()) assert True