Update static/demo/index.html
Browse files- static/demo/index.html +5 -41
static/demo/index.html
CHANGED
@@ -5,9 +5,10 @@
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<link rel="stylesheet" href="https://unpkg.com/carbon-components/css/carbon-components.min.css">
|
8 |
-
<script type="text/javascript" src="js/track.js"></script>
|
9 |
<script type="text/javascript" src="static/demo/js/d3.v7.min.js"></script>
|
10 |
-
|
|
|
|
|
11 |
<style type="text/css">
|
12 |
div.tooltip {
|
13 |
position: absolute;
|
@@ -66,7 +67,7 @@
|
|
66 |
</div>
|
67 |
</div>
|
68 |
</div>
|
69 |
-
<script
|
70 |
<script lang="javascript">
|
71 |
const width = 600;
|
72 |
const height = 200;
|
@@ -75,15 +76,12 @@
|
|
75 |
const marginBottom = 30;
|
76 |
const marginLeft = 30;
|
77 |
const nodeRadius = 3;
|
78 |
-
|
79 |
const svg = d3.select("#graph").append("svg")
|
80 |
.attr("viewBox", [0, 0, width, height])
|
81 |
.attr("style", "max-width: 100%; height: auto; font: 8px sans-serif;");
|
82 |
-
|
83 |
var tooltip = d3.select("body").append("div")
|
84 |
.attr("class", "tooltip")
|
85 |
.style("opacity", 0);
|
86 |
-
|
87 |
const renderGraph = (recommendations) => {
|
88 |
if( !recommendations ){
|
89 |
return ;
|
@@ -112,7 +110,6 @@
|
|
112 |
graphData.edges.push({ source: (i-1), target: i, type: 'input' });
|
113 |
}
|
114 |
}
|
115 |
-
|
116 |
// Adding nodes & edges for inclusion recommendations
|
117 |
if( recommendations['add'].length > 0 ){
|
118 |
for( j = 0; j < recommendations['add'].length; j++ ){
|
@@ -127,7 +124,6 @@
|
|
127 |
graphData.edges.push({ source: (i-1), target: (i+j+1), type: 'add' });
|
128 |
}
|
129 |
}
|
130 |
-
|
131 |
// Adding nodes & edges for removal recommendations
|
132 |
if( recommendations['remove'].length > 0 ){
|
133 |
// Showing only the first removal recommendation
|
@@ -140,30 +136,24 @@
|
|
140 |
type: 'remove'
|
141 |
});
|
142 |
}
|
143 |
-
|
144 |
// Convert edge references to actual node objects
|
145 |
graphData.edges = graphData.edges.map(edge => ({
|
146 |
source: graphData.nodes.find(n => n.id === edge.source),
|
147 |
target: graphData.nodes.find(n => n.id === edge.target)
|
148 |
}));
|
149 |
-
|
150 |
const { nodes, edges } = graphData;
|
151 |
-
|
152 |
// Prepare the ranges of values for the axes
|
153 |
const xDomain = d3.extent(nodes, d => d.x);
|
154 |
const yDomain = d3.extent(nodes, d => d.y);
|
155 |
const xPadding = 2
|
156 |
const yPadding = 2
|
157 |
-
|
158 |
// Prepare the scales for positional encoding.
|
159 |
const x = d3.scaleLinear()
|
160 |
.domain([xDomain[0]-xPadding,xDomain[1]+xPadding]).nice()
|
161 |
.range([marginLeft, width - marginRight]);
|
162 |
-
|
163 |
const y = d3.scaleLinear()
|
164 |
.domain([yDomain[0]-yPadding,yDomain[1]+yPadding]).nice()
|
165 |
.range([height - marginBottom, marginTop]);
|
166 |
-
|
167 |
// Create the axes.
|
168 |
svg.append("g")
|
169 |
.attr("transform", `translate(0,${height - marginBottom})`)
|
@@ -175,7 +165,6 @@
|
|
175 |
.attr("fill", "currentColor")
|
176 |
.attr("text-anchor", "end")
|
177 |
.text("Semantic dimension 1"));
|
178 |
-
|
179 |
svg.append("g")
|
180 |
.attr("transform", `translate(${marginLeft},0)`)
|
181 |
.call(d3.axisLeft(y))
|
@@ -186,7 +175,6 @@
|
|
186 |
.attr("fill", "currentColor")
|
187 |
.attr("text-anchor", "start")
|
188 |
.text("Semantic dimension 2"));
|
189 |
-
|
190 |
// Create the grid.
|
191 |
svg.append("g")
|
192 |
.attr("stroke", "#cccccc")
|
@@ -207,7 +195,6 @@
|
|
207 |
.attr("y2", d => 0.5 + y(d))
|
208 |
.attr("x1", marginLeft)
|
209 |
.attr("x2", width - marginRight));
|
210 |
-
|
211 |
// Add a layer of dots.
|
212 |
svg.append("g")
|
213 |
.attr("stroke-width", 2.5)
|
@@ -220,7 +207,6 @@
|
|
220 |
.attr("cx", d => x(d.x))
|
221 |
.attr("cy", d => y(d.y))
|
222 |
.attr("r", nodeRadius);
|
223 |
-
|
224 |
// Add a layer of labels.
|
225 |
svg.append("g")
|
226 |
.attr("font-family", "sans-serif")
|
@@ -260,7 +246,6 @@
|
|
260 |
.duration(50)
|
261 |
.style("opacity", 0);
|
262 |
});
|
263 |
-
|
264 |
// Adding edges
|
265 |
svg.append("g")
|
266 |
.selectAll("line")
|
@@ -273,18 +258,14 @@
|
|
273 |
.attr("x2", d => x(d.target.x)+(d.source.x>d.target.x?1.3*nodeRadius:nodeRadius*-1.3))
|
274 |
.attr("y2", d => y(d.target.y))
|
275 |
.style("stroke-dasharray", d => d.target.type == "add" ? "3,3" : "");
|
276 |
-
|
277 |
};
|
278 |
-
|
279 |
// ------------------------------------------------
|
280 |
-
|
281 |
// Init state
|
282 |
if( $( "#prompt" ).val() == "" ){
|
283 |
$( "#generate" ).attr( "disabled", true ) ;
|
284 |
}
|
285 |
var last_request = Date.now() - 60 * 60 * 1000 ;
|
286 |
var last_prompt = $( "#prompt" ).val().trim() ;
|
287 |
-
|
288 |
// Add recommendations to the prompt
|
289 |
function add_recommendation( p ){
|
290 |
preview_add_recommendation( p, "hide" )
|
@@ -292,7 +273,6 @@
|
|
292 |
$( "#recommendation" ).html( "" ) ;
|
293 |
$( "#prompt" ).trigger( "keyup" ) ; // Looking for recommendations after accepting a recommendation
|
294 |
}
|
295 |
-
|
296 |
// Preview for add recommendation
|
297 |
function preview_add_recommendation( p, flag ){
|
298 |
if( flag == "show" ){
|
@@ -302,7 +282,6 @@
|
|
302 |
$( "#prompt" ).val( $( "#prompt" ).val().replace( " " + p, "" ) ) ;
|
303 |
}
|
304 |
}
|
305 |
-
|
306 |
// Remove adversarial sentences from prompt
|
307 |
function remove_recommendation( p ){
|
308 |
$( "#prompt" ).val( $( "#prompt" ).val().replace( p, "" ) ) ;
|
@@ -310,7 +289,6 @@
|
|
310 |
$( "#recommendation" ).html( "" ) ;
|
311 |
$( "#prompt" ).trigger( "keyup" ) ; // Looking for recommendations after accepting a recommendation
|
312 |
}
|
313 |
-
|
314 |
// Preview for add recommendation
|
315 |
function preview_remove_recommendation( p, flag ){
|
316 |
if( flag == "show" ){
|
@@ -321,10 +299,8 @@
|
|
321 |
$( "#prompt" ).val( $( "#prompt" ).data( "previous_prompt" ) ) ;
|
322 |
}
|
323 |
}
|
324 |
-
|
325 |
// Listening to changes performed on the prompt input field
|
326 |
$( "#prompt" ).on( "keyup", function( e ){
|
327 |
-
|
328 |
// Updating the generate button state based on prompt length
|
329 |
if( $( "#prompt" ).val().length > 0 ){
|
330 |
$( "#generate" ).removeAttr( "disabled" ) ;
|
@@ -332,25 +308,21 @@
|
|
332 |
else{
|
333 |
$( "#generate" ).attr( "disabled", true ) ;
|
334 |
}
|
335 |
-
|
336 |
// Minimum timeout between the requests
|
337 |
if( Date.now() - last_request > 500 && last_prompt != $( "#prompt" ).val().trim() ){
|
338 |
last_request = Date.now() ;
|
339 |
last_prompt = $( "#prompt" ).val().trim() ;
|
340 |
// Getting the last typed char
|
341 |
var last_char = $( "#prompt" ).val().trim().slice( -1 ) ;
|
342 |
-
|
343 |
// Triggering the API request when ending of a sentence is found, e.g., .?!
|
344 |
if( last_char == "." || last_char == "?" || last_char == "!" ){
|
345 |
$( "#recommendation" ).html( 'Requesting recommendations: <div class="bx--tag bx--tag--gray bx--tag--deletable">...</div>' ) ;
|
346 |
var api_url = "/recommend?prompt="
|
347 |
// var api_url = "/recommend_local?prompt="
|
348 |
var p = $( "#prompt" ).val() ;
|
349 |
-
|
350 |
// API request
|
351 |
$.getJSON( api_url + encodeURI( p ), function( data ) {
|
352 |
$( "#recommendation" ).html( "Recommendations: " ) ;
|
353 |
-
|
354 |
// Looking first for removal recommendations
|
355 |
// if( data["remove"].length > 0 && data["remove"][0].similarity > 0.5 ){
|
356 |
if( data["remove"].length > 0 ){
|
@@ -363,7 +335,6 @@
|
|
363 |
break ; // Showing only once removal recommendation at a time
|
364 |
}
|
365 |
}
|
366 |
-
|
367 |
// else if( data["add"].length > 0 ){ // After the removal recommendations are dealt with, then we show recommendations for inclusion
|
368 |
if( data["add"].length > 0 ){ // Think Demo UX
|
369 |
for( var i = 0; i < data["add"].length; i++ ){
|
@@ -376,19 +347,16 @@
|
|
376 |
}
|
377 |
}
|
378 |
}
|
379 |
-
|
380 |
// User status message about recommendations found
|
381 |
if( data["add"].length == 0 && data["remove"].length == 0 ){
|
382 |
$( "#recommendation" ).html( "No recommendations found." ) ;
|
383 |
}
|
384 |
-
|
385 |
$("#prompt").data( "recommendations", data );
|
386 |
// renderGraph(data);
|
387 |
});
|
388 |
}
|
389 |
}
|
390 |
});
|
391 |
-
|
392 |
// Generation request
|
393 |
$( "#demo" ).on( "submit", function(e){ // Hugging Face
|
394 |
$( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
|
@@ -404,7 +372,6 @@
|
|
404 |
}
|
405 |
setTimeout( loading_animation, 500 );
|
406 |
} )()
|
407 |
-
|
408 |
$.ajax({
|
409 |
url: encodeURI("/demo_inference?prompt=" + $("#prompt").val()),
|
410 |
dataType: 'json',
|
@@ -414,18 +381,15 @@
|
|
414 |
console.log(data)
|
415 |
// Resetting the status of the button
|
416 |
$( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
|
417 |
-
|
418 |
// Clearing the previous timeout
|
419 |
if( $( "#demo" ).data( "timeoutId" ) != "" ){
|
420 |
clearTimeout( $( "#demo" ).data( "timeoutId" ) );
|
421 |
$( "#demo" ).data( "timeoutId", "" ) ;
|
422 |
}
|
423 |
-
|
424 |
out = data.content.split("");
|
425 |
model_id = data.model_id;
|
426 |
temperature = data.temperature
|
427 |
max_new_tokens = data.max_new_tokens
|
428 |
-
|
429 |
$( "#outcome" ).append( "\n\n+ ------------------------------------\n| Model: " + model_id + "\n| Temperature: " + temperature + "\n| Max new tokens: " + max_new_tokens + "\n+ ------------------------------------\n\n" ) ;
|
430 |
// Animating the generated output
|
431 |
( function typing_animation(){
|
@@ -448,4 +412,4 @@
|
|
448 |
</script>
|
449 |
<!-- <script src="https://unpkg.com/carbon-components/scripts/carbon-components.min.js"></script> -->
|
450 |
</body>
|
451 |
-
</html>
|
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<link rel="stylesheet" href="https://unpkg.com/carbon-components/css/carbon-components.min.css">
|
|
|
8 |
<script type="text/javascript" src="static/demo/js/d3.v7.min.js"></script>
|
9 |
+
<script type="text/javascript" src="static/demo/js/jquery-3.7.1.min.js"></script>
|
10 |
+
<!-- <script type="text/javascript" src="js/d3.v7.min.js"></script>
|
11 |
+
<script type="text/javascript" src="js/jquery-3.7.1.min.js"></script> -->
|
12 |
<style type="text/css">
|
13 |
div.tooltip {
|
14 |
position: absolute;
|
|
|
67 |
</div>
|
68 |
</div>
|
69 |
</div>
|
70 |
+
<script src="./js/jquery-3.7.1.min.js"></script>
|
71 |
<script lang="javascript">
|
72 |
const width = 600;
|
73 |
const height = 200;
|
|
|
76 |
const marginBottom = 30;
|
77 |
const marginLeft = 30;
|
78 |
const nodeRadius = 3;
|
|
|
79 |
const svg = d3.select("#graph").append("svg")
|
80 |
.attr("viewBox", [0, 0, width, height])
|
81 |
.attr("style", "max-width: 100%; height: auto; font: 8px sans-serif;");
|
|
|
82 |
var tooltip = d3.select("body").append("div")
|
83 |
.attr("class", "tooltip")
|
84 |
.style("opacity", 0);
|
|
|
85 |
const renderGraph = (recommendations) => {
|
86 |
if( !recommendations ){
|
87 |
return ;
|
|
|
110 |
graphData.edges.push({ source: (i-1), target: i, type: 'input' });
|
111 |
}
|
112 |
}
|
|
|
113 |
// Adding nodes & edges for inclusion recommendations
|
114 |
if( recommendations['add'].length > 0 ){
|
115 |
for( j = 0; j < recommendations['add'].length; j++ ){
|
|
|
124 |
graphData.edges.push({ source: (i-1), target: (i+j+1), type: 'add' });
|
125 |
}
|
126 |
}
|
|
|
127 |
// Adding nodes & edges for removal recommendations
|
128 |
if( recommendations['remove'].length > 0 ){
|
129 |
// Showing only the first removal recommendation
|
|
|
136 |
type: 'remove'
|
137 |
});
|
138 |
}
|
|
|
139 |
// Convert edge references to actual node objects
|
140 |
graphData.edges = graphData.edges.map(edge => ({
|
141 |
source: graphData.nodes.find(n => n.id === edge.source),
|
142 |
target: graphData.nodes.find(n => n.id === edge.target)
|
143 |
}));
|
|
|
144 |
const { nodes, edges } = graphData;
|
|
|
145 |
// Prepare the ranges of values for the axes
|
146 |
const xDomain = d3.extent(nodes, d => d.x);
|
147 |
const yDomain = d3.extent(nodes, d => d.y);
|
148 |
const xPadding = 2
|
149 |
const yPadding = 2
|
|
|
150 |
// Prepare the scales for positional encoding.
|
151 |
const x = d3.scaleLinear()
|
152 |
.domain([xDomain[0]-xPadding,xDomain[1]+xPadding]).nice()
|
153 |
.range([marginLeft, width - marginRight]);
|
|
|
154 |
const y = d3.scaleLinear()
|
155 |
.domain([yDomain[0]-yPadding,yDomain[1]+yPadding]).nice()
|
156 |
.range([height - marginBottom, marginTop]);
|
|
|
157 |
// Create the axes.
|
158 |
svg.append("g")
|
159 |
.attr("transform", `translate(0,${height - marginBottom})`)
|
|
|
165 |
.attr("fill", "currentColor")
|
166 |
.attr("text-anchor", "end")
|
167 |
.text("Semantic dimension 1"));
|
|
|
168 |
svg.append("g")
|
169 |
.attr("transform", `translate(${marginLeft},0)`)
|
170 |
.call(d3.axisLeft(y))
|
|
|
175 |
.attr("fill", "currentColor")
|
176 |
.attr("text-anchor", "start")
|
177 |
.text("Semantic dimension 2"));
|
|
|
178 |
// Create the grid.
|
179 |
svg.append("g")
|
180 |
.attr("stroke", "#cccccc")
|
|
|
195 |
.attr("y2", d => 0.5 + y(d))
|
196 |
.attr("x1", marginLeft)
|
197 |
.attr("x2", width - marginRight));
|
|
|
198 |
// Add a layer of dots.
|
199 |
svg.append("g")
|
200 |
.attr("stroke-width", 2.5)
|
|
|
207 |
.attr("cx", d => x(d.x))
|
208 |
.attr("cy", d => y(d.y))
|
209 |
.attr("r", nodeRadius);
|
|
|
210 |
// Add a layer of labels.
|
211 |
svg.append("g")
|
212 |
.attr("font-family", "sans-serif")
|
|
|
246 |
.duration(50)
|
247 |
.style("opacity", 0);
|
248 |
});
|
|
|
249 |
// Adding edges
|
250 |
svg.append("g")
|
251 |
.selectAll("line")
|
|
|
258 |
.attr("x2", d => x(d.target.x)+(d.source.x>d.target.x?1.3*nodeRadius:nodeRadius*-1.3))
|
259 |
.attr("y2", d => y(d.target.y))
|
260 |
.style("stroke-dasharray", d => d.target.type == "add" ? "3,3" : "");
|
|
|
261 |
};
|
|
|
262 |
// ------------------------------------------------
|
|
|
263 |
// Init state
|
264 |
if( $( "#prompt" ).val() == "" ){
|
265 |
$( "#generate" ).attr( "disabled", true ) ;
|
266 |
}
|
267 |
var last_request = Date.now() - 60 * 60 * 1000 ;
|
268 |
var last_prompt = $( "#prompt" ).val().trim() ;
|
|
|
269 |
// Add recommendations to the prompt
|
270 |
function add_recommendation( p ){
|
271 |
preview_add_recommendation( p, "hide" )
|
|
|
273 |
$( "#recommendation" ).html( "" ) ;
|
274 |
$( "#prompt" ).trigger( "keyup" ) ; // Looking for recommendations after accepting a recommendation
|
275 |
}
|
|
|
276 |
// Preview for add recommendation
|
277 |
function preview_add_recommendation( p, flag ){
|
278 |
if( flag == "show" ){
|
|
|
282 |
$( "#prompt" ).val( $( "#prompt" ).val().replace( " " + p, "" ) ) ;
|
283 |
}
|
284 |
}
|
|
|
285 |
// Remove adversarial sentences from prompt
|
286 |
function remove_recommendation( p ){
|
287 |
$( "#prompt" ).val( $( "#prompt" ).val().replace( p, "" ) ) ;
|
|
|
289 |
$( "#recommendation" ).html( "" ) ;
|
290 |
$( "#prompt" ).trigger( "keyup" ) ; // Looking for recommendations after accepting a recommendation
|
291 |
}
|
|
|
292 |
// Preview for add recommendation
|
293 |
function preview_remove_recommendation( p, flag ){
|
294 |
if( flag == "show" ){
|
|
|
299 |
$( "#prompt" ).val( $( "#prompt" ).data( "previous_prompt" ) ) ;
|
300 |
}
|
301 |
}
|
|
|
302 |
// Listening to changes performed on the prompt input field
|
303 |
$( "#prompt" ).on( "keyup", function( e ){
|
|
|
304 |
// Updating the generate button state based on prompt length
|
305 |
if( $( "#prompt" ).val().length > 0 ){
|
306 |
$( "#generate" ).removeAttr( "disabled" ) ;
|
|
|
308 |
else{
|
309 |
$( "#generate" ).attr( "disabled", true ) ;
|
310 |
}
|
|
|
311 |
// Minimum timeout between the requests
|
312 |
if( Date.now() - last_request > 500 && last_prompt != $( "#prompt" ).val().trim() ){
|
313 |
last_request = Date.now() ;
|
314 |
last_prompt = $( "#prompt" ).val().trim() ;
|
315 |
// Getting the last typed char
|
316 |
var last_char = $( "#prompt" ).val().trim().slice( -1 ) ;
|
|
|
317 |
// Triggering the API request when ending of a sentence is found, e.g., .?!
|
318 |
if( last_char == "." || last_char == "?" || last_char == "!" ){
|
319 |
$( "#recommendation" ).html( 'Requesting recommendations: <div class="bx--tag bx--tag--gray bx--tag--deletable">...</div>' ) ;
|
320 |
var api_url = "/recommend?prompt="
|
321 |
// var api_url = "/recommend_local?prompt="
|
322 |
var p = $( "#prompt" ).val() ;
|
|
|
323 |
// API request
|
324 |
$.getJSON( api_url + encodeURI( p ), function( data ) {
|
325 |
$( "#recommendation" ).html( "Recommendations: " ) ;
|
|
|
326 |
// Looking first for removal recommendations
|
327 |
// if( data["remove"].length > 0 && data["remove"][0].similarity > 0.5 ){
|
328 |
if( data["remove"].length > 0 ){
|
|
|
335 |
break ; // Showing only once removal recommendation at a time
|
336 |
}
|
337 |
}
|
|
|
338 |
// else if( data["add"].length > 0 ){ // After the removal recommendations are dealt with, then we show recommendations for inclusion
|
339 |
if( data["add"].length > 0 ){ // Think Demo UX
|
340 |
for( var i = 0; i < data["add"].length; i++ ){
|
|
|
347 |
}
|
348 |
}
|
349 |
}
|
|
|
350 |
// User status message about recommendations found
|
351 |
if( data["add"].length == 0 && data["remove"].length == 0 ){
|
352 |
$( "#recommendation" ).html( "No recommendations found." ) ;
|
353 |
}
|
|
|
354 |
$("#prompt").data( "recommendations", data );
|
355 |
// renderGraph(data);
|
356 |
});
|
357 |
}
|
358 |
}
|
359 |
});
|
|
|
360 |
// Generation request
|
361 |
$( "#demo" ).on( "submit", function(e){ // Hugging Face
|
362 |
$( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
|
|
|
372 |
}
|
373 |
setTimeout( loading_animation, 500 );
|
374 |
} )()
|
|
|
375 |
$.ajax({
|
376 |
url: encodeURI("/demo_inference?prompt=" + $("#prompt").val()),
|
377 |
dataType: 'json',
|
|
|
381 |
console.log(data)
|
382 |
// Resetting the status of the button
|
383 |
$( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
|
|
|
384 |
// Clearing the previous timeout
|
385 |
if( $( "#demo" ).data( "timeoutId" ) != "" ){
|
386 |
clearTimeout( $( "#demo" ).data( "timeoutId" ) );
|
387 |
$( "#demo" ).data( "timeoutId", "" ) ;
|
388 |
}
|
|
|
389 |
out = data.content.split("");
|
390 |
model_id = data.model_id;
|
391 |
temperature = data.temperature
|
392 |
max_new_tokens = data.max_new_tokens
|
|
|
393 |
$( "#outcome" ).append( "\n\n+ ------------------------------------\n| Model: " + model_id + "\n| Temperature: " + temperature + "\n| Max new tokens: " + max_new_tokens + "\n+ ------------------------------------\n\n" ) ;
|
394 |
// Animating the generated output
|
395 |
( function typing_animation(){
|
|
|
412 |
</script>
|
413 |
<!-- <script src="https://unpkg.com/carbon-components/scripts/carbon-components.min.js"></script> -->
|
414 |
</body>
|
415 |
+
</html>
|