Spaces:
Runtime error
Runtime error
Improve error handling.
Browse files- Dockerfile +1 -1
- app.R +18 -3
- model-session.R +1 -0
Dockerfile
CHANGED
@@ -25,6 +25,6 @@ RUN installGithub.r \
|
|
25 |
mlverse/minhub
|
26 |
|
27 |
|
|
|
28 |
COPY . .
|
29 |
-
|
30 |
CMD ["R", "--quiet", "-e", "shiny::runApp(host='0.0.0.0', port=7860)"]
|
|
|
25 |
mlverse/minhub
|
26 |
|
27 |
|
28 |
+
ENV HF_HOME="./cache/"
|
29 |
COPY . .
|
|
|
30 |
CMD ["R", "--quiet", "-e", "shiny::runApp(host='0.0.0.0', port=7860)"]
|
app.R
CHANGED
@@ -44,7 +44,7 @@ server <- function(input, output, session) {
|
|
44 |
return()
|
45 |
}
|
46 |
shinyjs::disable("send")
|
47 |
-
updateActionButton(inputId = "send", label = "Waiting for model")
|
48 |
insert_message(as.character(glue::glue("π€: {input$prompt}")))
|
49 |
|
50 |
# we modify the prompt to trigger the 'next_token' reactive
|
@@ -53,13 +53,21 @@ server <- function(input, output, session) {
|
|
53 |
|
54 |
next_token <- eventReactive(prompt(), ignoreInit = TRUE, {
|
55 |
prompt() %>%
|
56 |
-
sess$generate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
})
|
58 |
|
59 |
observeEvent(next_token(), {
|
60 |
tok <- next_token()
|
61 |
-
n_tokens(n_tokens() + 1)
|
62 |
|
|
|
63 |
tok %>% promises::then(function(tok) {
|
64 |
if (n_tokens() == 1) {
|
65 |
insert_message(paste0("π€: ", tok), append = FALSE)
|
@@ -87,14 +95,21 @@ server <- function(input, output, session) {
|
|
87 |
# Observer used at app startup time to allow using the 'Send' button once the
|
88 |
# model has been loaded.
|
89 |
observe({
|
|
|
|
|
|
|
|
|
90 |
model_loaded %>%
|
91 |
promises::then(onFulfilled = function(x) {
|
92 |
shinyjs::enable("send")
|
93 |
updateActionButton(inputId = "send", label = "Send")
|
|
|
94 |
}, onRejected = function(x) {
|
95 |
shinyjs::disable("send")
|
96 |
insert_message(paste0("π Error loading the model:\n", as.character(x)))
|
97 |
})
|
|
|
|
|
98 |
})
|
99 |
}
|
100 |
|
|
|
44 |
return()
|
45 |
}
|
46 |
shinyjs::disable("send")
|
47 |
+
updateActionButton(inputId = "send", label = "Waiting for model...")
|
48 |
insert_message(as.character(glue::glue("π€: {input$prompt}")))
|
49 |
|
50 |
# we modify the prompt to trigger the 'next_token' reactive
|
|
|
53 |
|
54 |
next_token <- eventReactive(prompt(), ignoreInit = TRUE, {
|
55 |
prompt() %>%
|
56 |
+
sess$generate() %>%
|
57 |
+
promises::then(
|
58 |
+
onFulfilled = function(x) {x},
|
59 |
+
onRejected = function(x) {
|
60 |
+
insert_message(paste0("π Error generating token.", as.character(x)))
|
61 |
+
updateActionButton(inputId = "send", label = "Failing generation. Contact admin.")
|
62 |
+
NULL
|
63 |
+
}
|
64 |
+
)
|
65 |
})
|
66 |
|
67 |
observeEvent(next_token(), {
|
68 |
tok <- next_token()
|
|
|
69 |
|
70 |
+
n_tokens(n_tokens() + 1)
|
71 |
tok %>% promises::then(function(tok) {
|
72 |
if (n_tokens() == 1) {
|
73 |
insert_message(paste0("π€: ", tok), append = FALSE)
|
|
|
95 |
# Observer used at app startup time to allow using the 'Send' button once the
|
96 |
# model has been loaded.
|
97 |
observe({
|
98 |
+
if (sess$is_loaded) return()
|
99 |
+
cat("Loading model:",sess$sess$poll_process(), "\n")
|
100 |
+
invalidateLater(1000, session)
|
101 |
+
|
102 |
model_loaded %>%
|
103 |
promises::then(onFulfilled = function(x) {
|
104 |
shinyjs::enable("send")
|
105 |
updateActionButton(inputId = "send", label = "Send")
|
106 |
+
sess$is_loaded <- TRUE
|
107 |
}, onRejected = function(x) {
|
108 |
shinyjs::disable("send")
|
109 |
insert_message(paste0("π Error loading the model:\n", as.character(x)))
|
110 |
})
|
111 |
+
|
112 |
+
NULL # we return NULL so we don't stuck waiting for the above.
|
113 |
})
|
114 |
}
|
115 |
|
model-session.R
CHANGED
@@ -9,6 +9,7 @@ model_session <- R6::R6Class(
|
|
9 |
self$sess <- promise_session$new()
|
10 |
self$temperature <- 1
|
11 |
self$top_k <- 50
|
|
|
12 |
},
|
13 |
load_model = function(repo) {
|
14 |
self$sess$call(args = list(repo = repo), function(repo) {
|
|
|
9 |
self$sess <- promise_session$new()
|
10 |
self$temperature <- 1
|
11 |
self$top_k <- 50
|
12 |
+
self$is_loaded <- FALSE
|
13 |
},
|
14 |
load_model = function(repo) {
|
15 |
self$sess$call(args = list(repo = repo), function(repo) {
|