dfalbel commited on
Commit
c29126b
1 Parent(s): 98fa2d0

Load model as part of the initial observer.

Browse files
Files changed (2) hide show
  1. app.R +9 -6
  2. model-session.R +1 -1
app.R CHANGED
@@ -34,8 +34,6 @@ ui <- page_fillable(
34
  )
35
 
36
  server <- function(input, output, session) {
37
- model_loaded <- sess$load_model(repo)
38
-
39
  prompt <- reactiveVal(value = system_prompt)
40
  n_tokens <- reactiveVal(value = 0)
41
 
@@ -88,11 +86,15 @@ server <- function(input, output, session) {
88
  # Observer used at app startup time to allow using the 'Send' button once the
89
  # model has been loaded.
90
  observe({
91
- if (is.null(sess$is_loaded) || sess$is_loaded) return()
92
- cat("Loading model:",sess$sess$poll_process(), "\n")
93
- invalidateLater(1000, session)
 
 
94
 
95
- model_loaded %>%
 
 
96
  promises::then(onFulfilled = function(x) {
97
  shinyjs::enable("send")
98
  updateActionButton(inputId = "send", label = "Send")
@@ -101,6 +103,7 @@ server <- function(input, output, session) {
101
  shinyjs::disable("send")
102
  insert_message(paste0("😭 Error loading the model:\n", as.character(x)))
103
  sess$is_loaded <- NULL # means failure!
 
104
  })
105
 
106
  NULL # we return NULL so we don't stuck waiting for the above.
 
34
  )
35
 
36
  server <- function(input, output, session) {
 
 
37
  prompt <- reactiveVal(value = system_prompt)
38
  n_tokens <- reactiveVal(value = 0)
39
 
 
86
  # Observer used at app startup time to allow using the 'Send' button once the
87
  # model has been loaded.
88
  observe({
89
+ if (!is.null(sess$is_loaded) && sess$is_loaded) return()
90
+ if (is.null(sess$is_loaded)) {
91
+ cat("Started loading model ....", "\n")
92
+ model_loaded <- sess$load_model(repo)
93
+ }
94
 
95
+ cat("Loading model:",sess$sess$poll_process(), "\n")
96
+ invalidateLater(5000, session)
97
+ model_loaded <- model_loaded %>%
98
  promises::then(onFulfilled = function(x) {
99
  shinyjs::enable("send")
100
  updateActionButton(inputId = "send", label = "Send")
 
103
  shinyjs::disable("send")
104
  insert_message(paste0("😭 Error loading the model:\n", as.character(x)))
105
  sess$is_loaded <- NULL # means failure!
106
+ sess$sess <- NULL
107
  })
108
 
109
  NULL # we return NULL so we don't stuck waiting for the above.
model-session.R CHANGED
@@ -9,7 +9,7 @@ model_session <- R6::R6Class(
9
  self$sess <- NULL
10
  self$temperature <- 1
11
  self$top_k <- 50
12
- self$is_loaded <- FALSE
13
  },
14
  load_model = function(repo) {
15
  if (!is.null(self$sess)) {
 
9
  self$sess <- NULL
10
  self$temperature <- 1
11
  self$top_k <- 50
12
+ self$is_loaded <- NULL
13
  },
14
  load_model = function(repo) {
15
  if (!is.null(self$sess)) {