Skip to content

Commit

Permalink
Simple uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomofkeima committed Nov 18, 2017
1 parent 9159030 commit c6817a2
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Expand Up @@ -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 = [
Expand Down
25 changes: 23 additions & 2 deletions 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()

13 changes: 13 additions & 0 deletions 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)
Empty file added src/moeflow/static/main.css
Empty file.
19 changes: 19 additions & 0 deletions src/moeflow/templates/main.html
@@ -0,0 +1,19 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>MoeFlow: Anime Characters Recognition</title>
<link rel="stylesheet" type="text/css" href="./static/main.css">
</head>
<body>
<h2>MoeFlow: Anime Characters Recognition (Alpha Ver.)</h2>
<p>For more information, see <a href="https://github.com/freedomofkeima/transfer-learning-anime" target="_blank">freedomofkeima/transfer-learning-anime</a> at Github.</p>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="uploaded_image" accept="image/*">
<input type="submit">
</form>
<div id="footer">
<p>Freedomofkeima Zone, 2017.</p>
</div>
</body>
</html>

6 changes: 3 additions & 3 deletions 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

0 comments on commit c6817a2

Please sign in to comment.