forked from ReidWilliams/GANs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
114 lines (97 loc) · 3.12 KB
/
Copy pathclient.js
File metadata and controls
114 lines (97 loc) · 3.12 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import PyFiClient from 'pyfi-client'
const py = PyFiClient()
let imgSize = {}
let baseChair = {}
let derivedChairs = {}
const button = document.getElementById('button')
const button_family = document.getElementById('button_family')
const result = document.getElementById('result')
const input = document.getElementById('input')
button.disabled = true
const loadImage = function(file_name, index){
let elem = document.createElement('img')
elem.setAttribute('src', `imgs/${file_name}`)
elem.setAttribute('data-vector-index', index)
document.getElementById('imageFrame').appendChild(elem)
}
const loadFamily = function(file_name, index){
let elem = document.createElement('img')
// document.getElementById('imageFrame').removeChild('img')
elem.setAttribute('src', `imgs/${file_name}`)
elem.setAttribute('familyImg', 'null')
elem.setAttribute('data-vector-index', index)
document.getElementById('familyFrame').appendChild(elem)
}
function removeImages() {
var images = [].slice.call(document.getElementsByTagName('img'), 0)
images.forEach(function(img) { // iterate the images array
img.parentNode.removeChild(img) // remove the child node via the parent node
});
}
function removeFamily() {
if (document.querySelectorAll('familyImg') == null) {
return "null";
} else {
var images = [].slice.call(document.querySelectorAll('familyImg'), 0)
console.log(images)
images.forEach(function(img) { // iterate the images array
img.parentNode.removeChild(img) // remove the child node via the parent node
})
return "Removed";
}
}
py._.onReady(()=>{
// wait until PyFi is ready to allow clicks
button.disabled = false
console.log('PyFi Ready!')
py.get_size([])
.then(size => {
console.log(size)
imgSize = size
})
})
button.addEventListener("click", function(event){
console.log('clicked initial generator!')
event.preventDefault()
event.stopPropagation()
button.disabled = true
removeImages()
py.generate_random_chair([])
.then(res => {
baseChair = res
loadImage(baseChair.file_name)
console.log('baseChair Set:',res)
button.disabled = false
})
.catch(error => {
console.log(error)
})
})
button_family.addEventListener("click", function(event){
event.preventDefault()
event.stopPropagation()
// button_family.disabled = true
let generationVector = baseChair.latent_vector
// look to see if the element has a data-vector-index attr,
// if so generate chairs based on that vector,
// otherwise assume it is the base vector
console.log('GENERATING FROM : baseChair.latent_vector', [baseChair.latent_vector])
// py.generate_random_chair([])
// .then(res => {
// console.log(res)
// loadImage(res.file_name)
py.generate_similar_chairs([baseChair.latent_vector])
.then(derivations => {
derivedChairs = derivations
removeFamily()
console.log('derivedChairs Set:',derivedChairs)
derivedChairs.file_names.forEach(function(file_name, index) {
loadFamily(file_name, index)
})
button_family.disabled = false
})
// })
.catch(error => {
console.log(error)
})
})