santanavagner commited on
Commit
d51e591
·
verified ·
1 Parent(s): 3b4b95f

Update static/demo/index.html

Browse files
Files changed (1) hide show
  1. static/demo/index.html +14 -32
static/demo/index.html CHANGED
@@ -391,22 +391,6 @@
391
 
392
  // Generation request
393
  $( "#demo" ).on( "submit", function(e){ // Hugging Face
394
-
395
- var out = "" ;
396
- const ajax_headers = {
397
- 'Content-Type': 'application/json',
398
- 'Accept': 'application/json',
399
- 'Access-Control-Allow-Headers': '*',
400
- 'Authorization' : 'Bearer <include-token-here>',
401
- };
402
- $.ajaxSetup({
403
- headers: ajax_headers
404
- });
405
-
406
- if( ajax_headers['Authorization'] == "Bearer <include-token-here>" ){
407
- console.error( "Please inform your authorization token in the ajax header setup." ) ;
408
- }
409
- else{
410
  $( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
411
  ( function loading_animation(){
412
  if( $( "#outcome" ).attr( "placeholder" ) == "" ){
@@ -421,21 +405,13 @@
421
  setTimeout( loading_animation, 500 );
422
  } )()
423
 
424
- var temperature = 0.5 ;
425
- var max_new_tokens = 1000 ;
426
- var model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
427
  $.ajax({
428
- type: "POST",
429
- url: "https://api-inference.huggingface.co/models/" + model_id,
430
- data: JSON.stringify({
431
- "inputs": $("#prompt").val(),
432
- "parameters": {
433
- "temperature": temperature,
434
- "max_new_tokens": max_new_tokens
435
- }
436
- }),
437
- crossDomain: true,
438
  success: function(data){
 
 
 
439
  // Resetting the status of the button
440
  $( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
441
 
@@ -445,7 +421,10 @@
445
  $( "#demo" ).data( "timeoutId", "" ) ;
446
  }
447
 
448
- out = data[0].generated_text.split("");
 
 
 
449
 
450
  $( "#outcome" ).append( "\n\n+ ------------------------------------\n| Model: " + model_id + "\n| Temperature: " + temperature + "\n| Max new tokens: " + max_new_tokens + "\n+ ------------------------------------\n\n" ) ;
451
  // Animating the generated output
@@ -457,9 +436,12 @@
457
  $( "#demo" ).data( "timeoutId", timeoutId ) ;
458
  }
459
  } )()
 
 
 
 
460
  }
461
- });
462
- }
463
  // Returning false so the form keeps user in the same page
464
  return false;
465
  });
 
391
 
392
  // Generation request
393
  $( "#demo" ).on( "submit", function(e){ // Hugging Face
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  $( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
395
  ( function loading_animation(){
396
  if( $( "#outcome" ).attr( "placeholder" ) == "" ){
 
405
  setTimeout( loading_animation, 500 );
406
  } )()
407
 
 
 
 
408
  $.ajax({
409
+ url: encodeURI("/demo_inference?prompt=" + $("#prompt").val()),
410
+ dataType: 'json',
 
 
 
 
 
 
 
 
411
  success: function(data){
412
+
413
+ console.log("Inference response")
414
+ console.log(data)
415
  // Resetting the status of the button
416
  $( "#generate" ).toggleClass( "bx--btn--disabled" ) ;
417
 
 
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
 
436
  $( "#demo" ).data( "timeoutId", timeoutId ) ;
437
  }
438
  } )()
439
+ },
440
+ error: function(data) {
441
+ out = data.responseJSON.error.message
442
+ $( "#outcome" ).val(out);
443
  }
444
+ })
 
445
  // Returning false so the form keeps user in the same page
446
  return false;
447
  });