-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (30 loc) · 1.08 KB
/
app.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
import json
import os
from pathlib import Path
from flask import Flask, request, render_template, jsonify
from store import FashionStore
app = Flask(__name__)
uploads_dir = os.path.join(app.instance_path, 'data')
app.config['MAX_CONTENT_PATH'] = 999999999
app.jinja_env.filters['to_json'] = lambda v: v.to_json()
@app.route("/", methods=('POST', 'GET'))
def index():
if request.method == 'POST':
uf = request.files['file']
if uf.filename != '':
uf.seek(0)
store = FashionStore()
store.parse_clothes(uf.read().decode('utf-8'))
dresses = store.dress()
return render_template('result.html', dresses=dresses)
return render_template("index.html")
@app.route("/wardrobe", methods=('GET',))
def wardrobe():
wardrobe_json = Path().joinpath("data").joinpath("wardrobe.json").absolute()
assert wardrobe_json.exists() and wardrobe_json.is_file()
with open(wardrobe_json, "r") as f:
data = json.loads(f.read())
return jsonify(
garments=data['garments'],
colors=data['colors'],
)