Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hainrich
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Konrad Völkel
hainrich
Commits
841fa33c
Commit
841fa33c
authored
2 months ago
by
Konrad Völkel
Browse files
Options
Downloads
Patches
Plain Diff
loading animation
parent
e2eb5b4e
No related branches found
No related tags found
No related merge requests found
Pipeline
#152361
passed
2 months ago
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+40
-2
40 additions, 2 deletions
index.js
semSearch.html
+1
-1
1 addition, 1 deletion
semSearch.html
worker.js
+6
-1
6 additions, 1 deletion
worker.js
with
47 additions
and
4 deletions
index.js
+
40
−
2
View file @
841fa33c
import
{
sendMessage
}
from
'
./modules/ui.js
'
;
import
{
sendMessage
}
from
'
./modules/ui.js
'
;
import
{
tokenizeText
}
from
'
./modules/semanticSearch.js
'
;
import
{
tokenizeText
,
initializeModel
}
from
'
./modules/semanticSearch.js
'
;
import
{
extractFAQfromHTML
}
from
'
./modules/faqData.js
'
;
import
{
extractFAQfromHTML
}
from
'
./modules/faqData.js
'
;
import
{
loadEmbedding
,
removeOutdatedEntries
}
from
'
./modules/embeddings.js
'
import
{
loadEmbedding
,
removeOutdatedEntries
}
from
'
./modules/embeddings.js
'
import
{
handleWorker
,
processQuery
}
from
'
./modules/workerInterface.js
'
import
{
handleWorker
,
processQuery
}
from
'
./modules/workerInterface.js
'
...
@@ -35,6 +35,20 @@ localStorage.setItem('smallEmbedding', JSON.stringify(tokenEmbeddingStack));
...
@@ -35,6 +35,20 @@ localStorage.setItem('smallEmbedding', JSON.stringify(tokenEmbeddingStack));
const
inputElement
=
document
.
getElementById
(
'
user-input
'
);
const
inputElement
=
document
.
getElementById
(
'
user-input
'
);
const
resultsContainer
=
document
.
getElementById
(
'
results
'
);
const
resultsContainer
=
document
.
getElementById
(
'
results
'
);
/** letting users know the site is not broken by showing them a loading animation until model is loaded */
let
dotCount
=
0
;
let
loadingAnimation
=
null
;
function
animateDots
()
{
dotCount
=
(
dotCount
+
1
)
%
4
;
let
dots
=
'
.
'
.
repeat
(
dotCount
);
inputElement
.
placeholder
=
`Loading
${
dots
}
`
;
loadingAnimation
=
setTimeout
(
animateDots
,
300
);
}
animateDots
();
let
topResult
=
null
;
let
topResult
=
null
;
inputElement
.
addEventListener
(
'
input
'
,
function
(
event
)
{
inputElement
.
addEventListener
(
'
input
'
,
function
(
event
)
{
const
query
=
event
.
target
.
value
.
trim
();
const
query
=
event
.
target
.
value
.
trim
();
...
@@ -112,7 +126,14 @@ export function linkAndClick(output) {
...
@@ -112,7 +126,14 @@ export function linkAndClick(output) {
},
250
);
},
250
);
}
}
worker
.
onmessage
=
(
events
)
=>
handleWorker
(
events
);
/** once model is initialized loading message is removed and user can start typing */
worker
.
addEventListener
(
'
message
'
,
function
(
events
)
{
if
(
events
.
data
.
type
===
'
ready
'
)
{
readyForInput
();
console
.
log
(
"
Ready
"
);
}
});
/** show results in chat window if "ask" is clicked */
/** show results in chat window if "ask" is clicked */
function
saveMessage
(){
function
saveMessage
(){
...
@@ -125,7 +146,24 @@ function sendAsk(){
...
@@ -125,7 +146,24 @@ function sendAsk(){
}
}
}
}
function
readyForInput
(){
clearTimeout
(
loadingAnimation
);
inputElement
.
disabled
=
false
;
inputElement
.
placeholder
=
"
Try asking: 'minimum admission grade' or 'I'm from outside the EU'
"
;
inputElement
.
focus
();
}
worker
.
onmessage
=
(
events
)
=>
handleWorker
(
events
);
window
.
sendAsk
=
sendAsk
;
window
.
sendAsk
=
sendAsk
;
/** give worker work */
/** give worker work */
worker
.
postMessage
({
act
:
'
initialize
'
,
textData
,
embeddingStack
,
tokenEmbeddingStack
});
worker
.
postMessage
({
act
:
'
initialize
'
,
textData
,
embeddingStack
,
tokenEmbeddingStack
});
This diff is collapsed.
Click to expand it.
semSearch.html
+
1
−
1
View file @
841fa33c
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
<div
id=
"messages"
></div>
<div
id=
"messages"
></div>
<div
id=
"messageInfo"
></div>
<div
id=
"messageInfo"
></div>
<div
id=
"input-container"
>
<div
id=
"input-container"
>
<input
type=
"text"
id=
"user-input"
placeholder=
"
Try asking: 'minimum admission grade' or 'I'm from outside the EU'"
>
<input
type=
"text"
id=
"user-input"
placeholder=
"
Loading"
disabled
>
<button
onclick=
"sendAsk()"
>
Ask
</button>
<button
onclick=
"sendAsk()"
>
Ask
</button>
...
...
This diff is collapsed.
Click to expand it.
worker.js
+
6
−
1
View file @
841fa33c
...
@@ -12,6 +12,8 @@ import {
...
@@ -12,6 +12,8 @@ import {
let
textData
=
[];
let
textData
=
[];
let
faqEmbeddings
=
[];
let
faqEmbeddings
=
[];
...
@@ -36,7 +38,10 @@ self.onmessage = async function (event) {
...
@@ -36,7 +38,10 @@ self.onmessage = async function (event) {
console
.
timeEnd
(
"
calcEmbeddings
"
);
console
.
timeEnd
(
"
calcEmbeddings
"
);
postMessage
({
act
:
'
initialized
'
,
embeddingCache
:
getEmbeddingCache
()
});
postMessage
({
act
:
'
initialized
'
,
embeddingCache
:
getEmbeddingCache
()
});
postMessage
({
act
:
'
tokeninit
'
,
tokenEmbeddingCache
:
getTokenEmbeddingCache
()
});
postMessage
({
act
:
'
tokeninit
'
,
tokenEmbeddingCache
:
getTokenEmbeddingCache
()
});
console
.
log
(
"
Ready
"
);
self
.
postMessage
({
type
:
'
ready
'
});
break
;
break
;
case
'
semanticSearch
'
:
case
'
semanticSearch
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment