-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.html
173 lines (153 loc) · 5.23 KB
/
search.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>ImageSearcher</title>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.js"></script>
<style>
body {
background-color: cadetblue;
}
.main-image-panel img {
display: block;
margin-left: auto;
margin-right: auto;
border-color: black;
width: 50%;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
grid-gap: 1rem;
max-width: 80rem;
margin: 5rem auto;
padding: 0 5rem;
}
.gallery-panel img {
width: 100%;
height: 22vw;
object-fit: cover;
border-radius: 0.75rem;
cursor: pointer;
}
#search-form {
padding-left: 20%;
padding-right: 20%;
background: #363636;
min-height: 80px;
height: 100vh;
display: flex;
align-items: center;
transition: 1s cubic-bezier(0.7, 0.28, 0.47, 1.15) height;
}
#search-form input {
margin-right: 5px;
width: 50%;
display: flex;
align-items: center;
}
#search-form.has-searched {
height: 6vh;
}
</style>
</head>
<body>
<div class="hero is-fullheight is-bold is-link" id="app">
<!-- SEARCH FORM -->
<form id="search-form" @submit.prevent="search" :class="{ 'has-searched': images }">
<input
type="text"
class="input is-medium"
placeholder="What images would you like to see? "
v-model="query">
<button
type="submit"
class="button is-link is-medium"
@click="setMainImage(null)">
{{ isSearching ? 'Searching' : 'Search' }}
</button>
</form>
<div class="hero-body">
<div class="container">
<!-- SEARCH RESULTS -->
<div v-if="images">
<div v-if="mainImage" class="main-image-panel">
<h3>{{this.mainImage}}</h3>
<img class="image"
@click="setMainImage(null)"
:src="'file://' + this.mainImage"
>
<h3>Same persons</h3>
<div class="gallery" v-for="(people, index) in faceImages">
<h3>Person {{index}}</h3>
<div class="gallery-panel" v-for="image in people">
<img class="image"
@click="setMainImage(image.image_path)"
:src="'file://' + image.image_path"
contain
width="500px">
</div>
</div>
</div>
<div class="gallery" v-else-if="images.length">
<div class="gallery-panel" v-for="image in images">
<img class="image"
@click="setMainImage(image.image_path)"
:src="'file://' + image.image_path"
contain
width="500px">
</div>
</div>
<h3 class="title has-text-centered is-1" v-if="!images.length && !isSearching">😖 No results found!</h3>
</div>
</div>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data() {
return {
apiUrl: 'http://127.0.0.1:5000/get_best_images',
apiUrlFaces: 'http://127.0.0.1:5000/get_closest_faces',
images: null,
faceImages: null,
mainImage: null,
isSearching: false,
query: ''
}
},
methods: {
search() {
if (this.query) {
this.images = [];
this.faceImages = []
this.isSearching = true;
const searchQuery = encodeURIComponent(this.query);
axios.get(`${this.apiUrl}?q=${searchQuery}`)
.then(res => {
this.images = res.data.results
this.isSearching = false;
})
}
},
setMainImage(path) {
console.log(path)
this.mainImage = path;
if (this.mainImage != null) {
const searchQuery = encodeURIComponent(path);
axios.get(`${this.apiUrlFaces}?q=${searchQuery}`)
.then(res => {
this.faceImages = res.data.results
})
window.scrollTo(0,0);
} else {
this.face_images = []
}
}
}
})
</script>
</body>
</html>