Skip to content

Commit 3b3ec13

Browse files
authored
Update versions to fix pex and npm build (rom1504#276)
* Update versions to fix pex and npm build * update all front deps * standard linting * Stop testing 3.7, test 3.11 instead * 3.10 instead of 3.11 * actual 3.10
1 parent 706a98b commit 3b3ec13

File tree

9 files changed

+88
-81
lines changed

9 files changed

+88
-81
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
strategy:
3333
matrix:
34-
python-version: [3.7, 3.8]
34+
python-version: ["3.8", "3.10"]
3535

3636
steps:
3737
- uses: actions/checkout@v2

Diff for: .github/workflows/front-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [14.x]
16+
node-version: [18.x]
1717

1818
steps:
1919
- uses: actions/checkout@v2

Diff for: .github/workflows/front-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Node.js
1414
uses: actions/setup-node@master
1515
with:
16-
node-version: 14.0.0
16+
node-version: 18.0.0
1717
- run: cd front && npm install
1818
- run: cd front && npm run build
1919
- run: cd front && npm test

Diff for: front/package.json

+23-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "server.js",
66
"dependencies": {
77
"compression": "^1.7.4",
8-
"express": "^4.17.1"
8+
"express": "^4.18.2"
99
},
1010
"repository": {
1111
"type": "git",
@@ -15,29 +15,29 @@
1515
"clip-retrieval-front": "./server.js"
1616
},
1717
"devDependencies": {
18-
"@vaadin/vaadin-button": "^2.4.0",
19-
"@vaadin/vaadin-combo-box": "^6.0.1",
20-
"@vaadin/vaadin-select": "^3.0.0",
21-
"@webcomponents/webcomponentsjs": "^2.2.4",
22-
"bootstrap": "^4.5.2",
23-
"dateformat": "^3.0.3",
18+
"@vaadin/vaadin-button": "^23.3.14",
19+
"@vaadin/vaadin-combo-box": "^23.3.14",
20+
"@vaadin/vaadin-select": "^23.3.14",
21+
"@webcomponents/webcomponentsjs": "^2.8.0",
22+
"bootstrap": "^5.2.3",
23+
"clean-webpack-plugin": "^4.0.0",
24+
"copy-webpack-plugin": "^11.0.0",
25+
"css-loader": "^6.8.1",
26+
"dateformat": "^5.0.3",
27+
"file-loader": "^6.2.0",
28+
"html-webpack-plugin": "^5.5.1",
29+
"http-server": "^14.1.1",
2430
"json-bigint": "^1.0.0",
25-
"lit-element": "^2.0.1",
26-
"lit-html": "^1.0.0",
27-
"clean-webpack-plugin": "^0.1.19",
28-
"copy-webpack-plugin": "^4.5.2",
29-
"css-loader": "^2.1.0",
30-
"file-loader": "^3.0.1",
31-
"html-webpack-plugin": "^4.0.0-alpha",
32-
"http-server": "^0.11.1",
33-
"raw-loader": "^1.0.0",
34-
"standard": "^12.0.1",
35-
"style-loader": "^0.23.1",
36-
"to-string-loader": "^1.1.5",
37-
"webpack": "^4.14.0",
38-
"webpack-cli": "^3.0.8",
39-
"webpack-dev-server": "^3.1.4",
40-
"webpack-merge": "^4.1.3"
31+
"lit-element": "^3.3.2",
32+
"lit-html": "^2.7.4",
33+
"raw-loader": "^4.0.2",
34+
"standard": "^17.0.0",
35+
"style-loader": "^3.3.3",
36+
"to-string-loader": "^1.2.0",
37+
"webpack": "^5.84.1",
38+
"webpack-cli": "^5.1.1",
39+
"webpack-dev-server": "^4.15.0",
40+
"webpack-merge": "^5.9.0"
4141
},
4242
"scripts": {
4343
"build": "webpack --env production",

Diff for: front/src/clip-front.js

+32-22
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ClipFront extends LitElement {
1313
})
1414
}
1515

16-
init () {
16+
async init () {
1717
const urlParams = new URLSearchParams(window.location.search)
1818
const back = urlParams.get('back')
1919
const index = urlParams.get('index')
@@ -61,16 +61,17 @@ class ClipFront extends LitElement {
6161
this.hideDuplicateImages = true
6262
this.aestheticScore = ''
6363
this.aestheticWeight = '0.5'
64-
this.initIndices()
64+
await this.initIndices()
65+
this.postInit()
6566
}
6667

6768
setBackendToDefault () {
6869
this.backendHost = this.defaultBackend
6970
this.initIndices(true)
7071
}
7172

72-
initIndices (forceChange) {
73-
this.service.getIndices().then(l => {
73+
async initIndices (forceChange) {
74+
await this.service.getIndices().then(l => {
7475
this.indices = l
7576
if (forceChange || this.currentIndex === '') {
7677
this.currentIndex = this.indices[0]
@@ -109,7 +110,7 @@ class ClipFront extends LitElement {
109110
}
110111
}
111112

112-
firstUpdated () {
113+
postInit () {
113114
const searchElem = this.shadowRoot.getElementById('searchBar')
114115
searchElem.addEventListener('keyup', e => { if (e.keyCode === 13) { this.textSearch() } })
115116
const productsElement = this.shadowRoot.getElementById('products')
@@ -234,7 +235,7 @@ class ClipFront extends LitElement {
234235

235236
async download () {
236237
function downloadFile (filename, text) {
237-
var element = document.createElement('a')
238+
const element = document.createElement('a')
238239
element.setAttribute('href', 'data:application/json;charset=utf-8,' + encodeURIComponent(text))
239240
element.setAttribute('download', filename)
240241

@@ -288,6 +289,7 @@ class ClipFront extends LitElement {
288289
this.setUrlParams()
289290
setTimeout(() => this.initialScroll(), 0)
290291
}
292+
291293
static get styles () {
292294
return css`
293295
input:-webkit-autofill,
@@ -458,7 +460,7 @@ class ClipFront extends LitElement {
458460
}
459461

460462
updateImage (file) {
461-
var reader = new FileReader()
463+
const reader = new FileReader()
462464
reader.readAsDataURL(file)
463465
reader.onload = () => {
464466
this.image = reader.result.split(',')[1]
@@ -470,8 +472,8 @@ class ClipFront extends LitElement {
470472

471473
renderImage (image) {
472474
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}`
475477
}
476478
if (image[this.urlColumn] !== undefined) {
477479
src = image[this.urlColumn]
@@ -486,24 +488,29 @@ class ClipFront extends LitElement {
486488
return html`
487489
<figure style="margin:5px;display:table"
488490
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+
: ''}
492495
493496
<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
496499
} else if (image[this.urlColumn] !== undefined) {
497500
this.imageUrl = image[this.urlColumn]
498501
}
499502
}} />
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 : ''}"
502505
@error=${() => { this.blacklist = { ...this.blacklist, ...{ [src]: true } } }} />
503506
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+
: ''}
507514
508515
509516
</figure>
@@ -525,8 +532,11 @@ class ClipFront extends LitElement {
525532
}
526533

527534
render () {
535+
if (this.images === undefined) {
536+
return html`<div id="all"></div>`
537+
}
528538
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)
530540
const filteredImages = this.hideDuplicateUrls ? this.filterDuplicateUrls(preFiltered) : preFiltered
531541

532542
return html`
@@ -546,8 +556,8 @@ class ClipFront extends LitElement {
546556
Backend url: <br /><input type="text" style="width:80px" value=${this.backendHost} @input=${e => { this.backendHost = e.target.value }}/><br />
547557
Index: <br /><select style="margin-bottom:50px;" @input=${e => { this.currentIndex = e.target.value }}>${this.indices.map(index =>
548558
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 />` : ''}
551561
<a href="https://github.com/rom1504/clip-retrieval">Clip retrieval</a> works by converting the text query to a CLIP embedding
552562
, then using that embedding to query a knn index of clip image embedddings<br /><br />
553563
<label>Display captions<input type="checkbox" ?checked="${this.displayCaptions}" @click=${() => { this.displayCaptions = !this.displayCaptions }} /></label><br />

Diff for: front/src/clip-service.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@ export default class ClipService {
88
}
99

1010
async getIndices () {
11-
const result = JsonBigint.parse(await (await fetch(this.backend + `/indices-list`, {
11+
const result = JsonBigint.parse(await (await fetch(this.backend + '/indices-list', {
1212
})).text())
1313

1414
return result
1515
}
1616

1717
async callClipService (text, image, imageUrl, embeddingInput, modality, numImages, indexName, numResultIds, useMclip, hideDuplicateImages, useSafetyModel, useViolenceDetector, aestheticScore, aestheticWeight) {
1818
console.log('calling', text, numImages)
19-
const result = JsonBigint.parse(await (await fetch(this.backend + `/knn-service`, {
19+
const result = JsonBigint.parse(await (await fetch(this.backend + '/knn-service', {
2020
method: 'POST',
2121
body: JSON.stringify({
2222
text,
2323
image,
24-
'image_url': imageUrl,
25-
'embedding_input': embeddingInput,
24+
image_url: imageUrl,
25+
embedding_input: embeddingInput,
2626
modality,
27-
'num_images': numImages,
28-
'indice_name': indexName,
29-
'num_result_ids': numResultIds,
30-
'use_mclip': useMclip,
31-
'deduplicate': hideDuplicateImages,
32-
'use_safety_model': useSafetyModel,
33-
'use_violence_detector': useViolenceDetector,
34-
'aesthetic_score': aestheticScore,
35-
'aesthetic_weight': aestheticWeight
27+
num_images: numImages,
28+
indice_name: indexName,
29+
num_result_ids: numResultIds,
30+
use_mclip: useMclip,
31+
deduplicate: hideDuplicateImages,
32+
use_safety_model: useSafetyModel,
33+
use_violence_detector: useViolenceDetector,
34+
aesthetic_score: aestheticScore,
35+
aesthetic_weight: aestheticWeight
3636
})
3737
})).text())
3838

3939
return result
4040
}
4141

4242
async getMetadata (ids, indexName) {
43-
const result = JsonBigint.parse(await (await fetch(this.backend + `/metadata`, {
43+
const result = JsonBigint.parse(await (await fetch(this.backend + '/metadata', {
4444
method: 'POST',
4545
body: JSON.stringify({
4646
ids,
47-
'indice_name': indexName
47+
indice_name: indexName
4848
})
4949
})).text())
5050

Diff for: front/webpack.config.js

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22

33
const { resolve, join } = require('path')
4-
const merge = require('webpack-merge')
4+
const { merge } = require('webpack-merge')
55
const CopyWebpackPlugin = require('copy-webpack-plugin')
66
const HtmlWebpackPlugin = require('html-webpack-plugin')
7-
const CleanWebpackPlugin = require('clean-webpack-plugin')
7+
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
88

99
const ENV = process.argv.find(arg => arg.includes('production'))
1010
? 'production'
@@ -28,18 +28,15 @@ const assets = [
2828
const polyfills = [
2929
{
3030
from: resolve(`${webcomponentsjs}/webcomponents-*.js`),
31-
to: join(OUTPUT_PATH, 'vendor'),
32-
flatten: true
31+
to: join(OUTPUT_PATH, 'vendor')
3332
},
3433
{
3534
from: resolve(`${webcomponentsjs}/bundles/*.js`),
36-
to: join(OUTPUT_PATH, 'vendor', 'bundles'),
37-
flatten: true
35+
to: join(OUTPUT_PATH, 'vendor', 'bundles')
3836
},
3937
{
4038
from: resolve(`${webcomponentsjs}/custom-elements-es5-adapter.js`),
41-
to: join(OUTPUT_PATH, 'vendor'),
42-
flatten: true
39+
to: join(OUTPUT_PATH, 'vendor')
4340
}
4441
]
4542

@@ -79,19 +76,16 @@ const developmentConfig = merge([
7976
{
8077
devtool: 'cheap-module-source-map',
8178
plugins: [
82-
new CopyWebpackPlugin([...polyfills, ...assets]),
79+
new CopyWebpackPlugin({ patterns: [...polyfills, ...assets] }),
8380
new HtmlWebpackPlugin({
8481
template: INDEX_TEMPLATE
8582
})
8683
],
8784

8885
devServer: {
89-
contentBase: OUTPUT_PATH,
9086
compress: true,
91-
overlay: true,
9287
port: 3005,
9388
historyApiFallback: true,
94-
disableHostCheck: true,
9589
host: '0.0.0.0'
9690
}
9791
}
@@ -101,8 +95,8 @@ const productionConfig = merge([
10195
{
10296
devtool: 'nosources-source-map',
10397
plugins: [
104-
new CleanWebpackPlugin([OUTPUT_PATH], { verbose: true }),
105-
new CopyWebpackPlugin([...polyfills, ...assets]),
98+
new CleanWebpackPlugin(),
99+
new CopyWebpackPlugin({ patterns: [...polyfills, ...assets] }),
106100
new HtmlWebpackPlugin({
107101
template: INDEX_TEMPLATE,
108102
filename: 'index.html',
@@ -118,9 +112,10 @@ const productionConfig = merge([
118112
])
119113

120114
module.exports = mode => {
121-
if (mode === 'production') {
122-
return merge(commonConfig, productionConfig, { mode })
115+
if (mode.production) {
116+
return merge(commonConfig, productionConfig, { mode: 'production' })
123117
}
118+
const config = merge(commonConfig, developmentConfig, { mode: 'development' })
124119

125-
return merge(commonConfig, developmentConfig, { mode })
120+
return config
126121
}

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ open-clip-torch>=2.0.0,<3.0.0
2222
requests>=2.27.1,<3
2323
aiohttp>=3.8.1,<4
2424
multilingual-clip>=1.0.10,<2
25+
urllib3<2
26+
scipy<1.9.2

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def _read_reqs(relpath):
4848
"Intended Audience :: Developers",
4949
"Topic :: Scientific/Engineering :: Artificial Intelligence",
5050
"License :: OSI Approved :: MIT License",
51-
"Programming Language :: Python :: 3.6",
51+
"Programming Language :: Python :: 3.8",
5252
],
5353
)

0 commit comments

Comments
 (0)