-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
75 lines (54 loc) · 1.84 KB
/
__init__.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sqlite3
import pickle
from math import ceil
from paletteutils import hex2Lab, extendpal
from flask import Flask ,render_template
# load kdtree of artworks from pixeljoint
f = open('pixeljoint.pickle', 'rb')
tree = pickle.load(f)
app = Flask(__name__)
@app.route("/")
def home():
# default/homepage palette
c1 = '250647'
c2 = 'eba834'
c3 = '9a243b'
c4 = 'none'
c5 = 'none'
return searchpalette(c1, c2, c3, c4, c5)
@app.route("/details/pixelart/<id>")
def detailspj(id):
# connect to Pelgine db
conn = sqlite3.connect("pelgine.db")
cursor = conn.cursor()
sql = "select * from pixeljoint where rowid = {} ".format(id)
cursor.execute(sql)
details = list(cursor.fetchone())
conn.close()
return render_template("details.html", artwork= details )
@app.route("/search/pixelart/<c1>-<c2>-<c3>-<c4>-<c5>")
def searchpalette(c1,c2,c3,c4,c5):
# connect to Pelgine db
conn = sqlite3.connect("pelgine.db")
cursor = conn.cursor()
# Example Search : http://127.0.0.1:5000/search/pixelart/9D1D23-ff5e00-ffd914-6d2222-d94c0f
pal = [c1,c2,c3,c4,c5]
pal = ["#"+color for color in pal if color != 'none']
epal = extendpal(pal, 5)
# search k-d tree and put results in artworks
idurl = []
search = hex2Lab(epal)
results = tree.query(search, k=500, p=2)
artworkids= {}
for index in results[1]:
# calculate id of artwork
id = int(ceil(((index + 1) / 120)))
if id not in artworkids:
artworkids[id] = 1
sql = "select imgUrl from pixeljoint where rowid = {} ".format(id)
cursor.execute(sql)
idurl.append([id, cursor.fetchone()[0]])
conn.close()
return render_template("search.html", pal=[], artworks= idurl, palette= pal, numcolors=len(pal))
if __name__ == "__main__":
app.run()