@@ -38,7 +38,19 @@ function showStatus(message, isError = false) {
3838 setTimeout ( ( ) => status . style . display = 'none' , 3000 ) ;
3939}
4040
41+ async function load_model ( checkpoint ) {
42+ const model = await rlt . load ( checkpoint )
43+ document . getElementById ( "checkpoint-name" ) . textContent = model . checkpoint_name
44+ document . getElementById ( "observations" ) . textContent = model . meta . environment . observation . split ( "." ) . join ( ", " )
45+ document . getElementById ( "observations" ) . title = model . meta . environment . observation . split ( "." ) . join ( ", " )
46+ return model
47+ }
48+
4149async function main ( ) {
50+ document . getElementById ( "default-checkpoint-btn" ) . addEventListener ( "click" , async ( ) => {
51+ model = await load_model ( file_url )
52+ } )
53+
4254 const seed = 12
4355 if ( model === null ) {
4456 let checkpoint = null
@@ -51,10 +63,7 @@ async function main(){
5163 checkpoint = await ( await fetch ( file_url ) ) . arrayBuffer ( )
5264 localStorage . setItem ( "checkpoint" , arrayBufferToBase64 ( checkpoint ) )
5365 }
54- model = await rlt . load ( checkpoint )
55- document . getElementById ( "checkpoint-name" ) . textContent = model . checkpoint_name
56- document . getElementById ( "observations" ) . textContent = model . meta . environment . observation . split ( "." ) . join ( ", " )
57- document . getElementById ( "observations" ) . title = model . meta . environment . observation . split ( "." ) . join ( ", " )
66+ model = await load_model ( checkpoint )
5867 }
5968 const policy_state = {
6069 "step" : 0
@@ -147,13 +156,10 @@ document.body.addEventListener('drop', e => {
147156 const file = e . dataTransfer . files [ 0 ] ;
148157 if ( file ) {
149158 const reader = new FileReader ( ) ;
150- reader . onload = function ( e ) {
159+ reader . onload = async function ( e ) {
151160 const array_buffer = e . target . result ;
152161 localStorage . setItem ( "checkpoint" , arrayBufferToBase64 ( array_buffer ) )
153- model = rlt . load ( array_buffer )
154- document . getElementById ( "checkpoint-name" ) . textContent = model . checkpoint_name
155- document . getElementById ( "observations" ) . textContent = model . meta . environment . observation . split ( "." ) . join ( ", " )
156- document . getElementById ( "observations" ) . title = model . meta . environment . observation . split ( "." ) . join ( ", " )
162+ model = await load_model ( array_buffer )
157163 console . log ( "loaded model: " , model . checkpoint_name )
158164 showStatus ( `Loaded model: ${ model . checkpoint_name } ` ) ;
159165 } ;
0 commit comments