@@ -13,7 +13,7 @@ class ClipFront extends LitElement {
13
13
} )
14
14
}
15
15
16
- init ( ) {
16
+ async init ( ) {
17
17
const urlParams = new URLSearchParams ( window . location . search )
18
18
const back = urlParams . get ( 'back' )
19
19
const index = urlParams . get ( 'index' )
@@ -61,16 +61,17 @@ class ClipFront extends LitElement {
61
61
this . hideDuplicateImages = true
62
62
this . aestheticScore = ''
63
63
this . aestheticWeight = '0.5'
64
- this . initIndices ( )
64
+ await this . initIndices ( )
65
+ this . postInit ( )
65
66
}
66
67
67
68
setBackendToDefault ( ) {
68
69
this . backendHost = this . defaultBackend
69
70
this . initIndices ( true )
70
71
}
71
72
72
- initIndices ( forceChange ) {
73
- this . service . getIndices ( ) . then ( l => {
73
+ async initIndices ( forceChange ) {
74
+ await this . service . getIndices ( ) . then ( l => {
74
75
this . indices = l
75
76
if ( forceChange || this . currentIndex === '' ) {
76
77
this . currentIndex = this . indices [ 0 ]
@@ -109,7 +110,7 @@ class ClipFront extends LitElement {
109
110
}
110
111
}
111
112
112
- firstUpdated ( ) {
113
+ postInit ( ) {
113
114
const searchElem = this . shadowRoot . getElementById ( 'searchBar' )
114
115
searchElem . addEventListener ( 'keyup' , e => { if ( e . keyCode === 13 ) { this . textSearch ( ) } } )
115
116
const productsElement = this . shadowRoot . getElementById ( 'products' )
@@ -234,7 +235,7 @@ class ClipFront extends LitElement {
234
235
235
236
async download ( ) {
236
237
function downloadFile ( filename , text ) {
237
- var element = document . createElement ( 'a' )
238
+ const element = document . createElement ( 'a' )
238
239
element . setAttribute ( 'href' , 'data:application/json;charset=utf-8,' + encodeURIComponent ( text ) )
239
240
element . setAttribute ( 'download' , filename )
240
241
@@ -288,6 +289,7 @@ class ClipFront extends LitElement {
288
289
this . setUrlParams ( )
289
290
setTimeout ( ( ) => this . initialScroll ( ) , 0 )
290
291
}
292
+
291
293
static get styles ( ) {
292
294
return css `
293
295
input:-webkit-autofill,
@@ -458,7 +460,7 @@ class ClipFront extends LitElement {
458
460
}
459
461
460
462
updateImage ( file ) {
461
- var reader = new FileReader ( )
463
+ const reader = new FileReader ( )
462
464
reader . readAsDataURL ( file )
463
465
reader . onload = ( ) => {
464
466
this . image = reader . result . split ( ',' ) [ 1 ]
@@ -470,8 +472,8 @@ class ClipFront extends LitElement {
470
472
471
473
renderImage ( image ) {
472
474
let src
473
- if ( image [ ' image' ] !== undefined ) {
474
- src = `data:image/png;base64, ${ image [ ' image' ] } `
475
+ if ( image . image !== undefined ) {
476
+ src = `data:image/png;base64, ${ image . image } `
475
477
}
476
478
if ( image [ this . urlColumn ] !== undefined ) {
477
479
src = image [ this . urlColumn ]
@@ -486,24 +488,29 @@ class ClipFront extends LitElement {
486
488
return html `
487
489
< figure style ="margin:5px;display:table "
488
490
style =${ 'margin:1px; ' + ( this . blacklist [ src ] !== undefined ? 'display:none' : 'display:inline' ) } >
489
- ${ this . displaySimilarities ? html `< p > ${ ( image [ 'similarity' ] ) . toFixed ( 4 ) } </ p > ` : `` }
490
- ${ image [ 'caption' ] !== undefined
491
- ? html `< img src ="assets/search.png " class ="subTextSearch " @click =${ ( ) => { this . text = image [ 'caption' ] ; this . textSearch ( ) } } / > ` : `` }
491
+ ${ this . displaySimilarities ? html `< p > ${ ( image . similarity ) . toFixed ( 4 ) } </ p > ` : '' }
492
+ ${ image . caption !== undefined
493
+ ? html `< img src ="assets/search.png " class ="subTextSearch " @click =${ ( ) => { this . text = image . caption ; this . textSearch ( ) } } / > `
494
+ : '' }
492
495
493
496
< img src ="assets/image-search.png " class ="subImageSearch " @click =${ ( ) => {
494
- if ( image [ ' image' ] !== undefined ) {
495
- this . image = image [ ' image' ]
497
+ if ( image . image !== undefined ) {
498
+ this . image = image . image
496
499
} else if ( image [ this . urlColumn ] !== undefined ) {
497
500
this . imageUrl = image [ this . urlColumn ]
498
501
}
499
502
} } / >
500
- < img class ="pic " src ="${ src } " alt ="${ image [ ' caption' ] !== undefined ? image [ ' caption' ] : '' } ""
501
- title="${ image [ ' caption' ] !== undefined ? image [ ' caption' ] : '' } "
503
+ < img class ="pic " src ="${ src } " alt ="${ image . caption !== undefined ? image . caption : '' } ""
504
+ title="${ image . caption !== undefined ? image . caption : '' } "
502
505
@error=${ ( ) => { this . blacklist = { ...this . blacklist , ...{ [ src ] : true } } } } />
503
506
504
- ${ this . displayCaptions ? html `< figcaption >
505
- ${ image [ 'caption' ] !== undefined && image [ 'caption' ] . length > 50 &&
506
- ! this . displayFullCaptions ? image [ 'caption' ] . substr ( 0 , 50 ) + '...' : image [ 'caption' ] } </ figcaption > ` : '' }
507
+ ${ this . displayCaptions
508
+ ? html `< figcaption >
509
+ ${ image . caption !== undefined && image . caption . length > 50 &&
510
+ ! this . displayFullCaptions
511
+ ? image . caption . substr ( 0 , 50 ) + '...'
512
+ : image . caption } </ figcaption > `
513
+ : '' }
507
514
508
515
509
516
</ figure >
@@ -525,8 +532,11 @@ class ClipFront extends LitElement {
525
532
}
526
533
527
534
render ( ) {
535
+ if ( this . images === undefined ) {
536
+ return html `< div id ="all "> </ div > `
537
+ }
528
538
const preFiltered = this . images
529
- . filter ( image => image [ ' caption' ] !== undefined || image [ this . urlColumn ] !== undefined || image [ ' image' ] !== undefined )
539
+ . filter ( image => image . caption !== undefined || image [ this . urlColumn ] !== undefined || image . image !== undefined )
530
540
const filteredImages = this . hideDuplicateUrls ? this . filterDuplicateUrls ( preFiltered ) : preFiltered
531
541
532
542
return html `
@@ -546,8 +556,8 @@ class ClipFront extends LitElement {
546
556
Backend url: < br /> < input type ="text " style ="width:80px " value =${ this . backendHost } @input =${ e => { this . backendHost = e . target . value } } /> < br />
547
557
Index: < br /> < select style ="margin-bottom:50px; " @input =${ e => { this . currentIndex = e . target . value } } > ${ this . indices . map ( index =>
548
558
html `< option value =${ index } ?selected =${ index === this . currentIndex } > ${ index } </ option > ` ) } </ select > < br />
549
- ${ this . image !== undefined ? html `< img width ="100px " src ="data:image/png;base64, ${ this . image } "" /> < br /> ` : `` }
550
- ${ this . imageUrl !== undefined ? html `< img width ="100px " src ="${ this . imageUrl } "" /> < br /> ` : `` }
559
+ ${ this . image !== undefined ? html `< img width ="100px " src ="data:image/png;base64, ${ this . image } "" /> < br /> ` : '' }
560
+ ${ this . imageUrl !== undefined ? html `< img width ="100px " src ="${ this . imageUrl } "" /> < br /> ` : '' }
551
561
< a href ="https://github.com/rom1504/clip-retrieval "> Clip retrieval</ a > works by converting the text query to a CLIP embedding
552
562
, then using that embedding to query a knn index of clip image embedddings< br /> < br />
553
563
< label > Display captions< input type ="checkbox " ?checked ="${ this . displayCaptions } " @click =${ ( ) => { this . displayCaptions = ! this . displayCaptions } } / > </ label > < br />
0 commit comments