cjerzak commited on
Commit
b24a241
·
verified ·
1 Parent(s): 152aa3f

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +12 -41
app.R CHANGED
@@ -29,6 +29,18 @@ suppressPackageStartupMessages({
29
  library(shinyWidgets)
30
  })
31
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # Optional tooltips (if bsplus is available)
33
  has_bsplus <- requireNamespace("bsplus", quietly = TRUE)
34
  if (has_bsplus) {
@@ -241,43 +253,6 @@ server <- function(input, output, session) {
241
  updateTextAreaInput(session, "text_names", value = "Google\nAlphabet Inc.\nMicrosoft\nMeta Platforms\nOpenAI")
242
  })
243
 
244
- # Backend setup ---------------------------------------------------------------
245
- safe_build_backend <- function(conda_arg) {
246
- if (!requireNamespace("LinkOrgs", quietly = TRUE)) {
247
- notify("Package 'LinkOrgs' not installed. Please install it via devtools::install_github('cjerzak/LinkOrgs-software/LinkOrgs').", "error", 10)
248
- cat("[LinkOrgs missing] Install with devtools::install_github('cjerzak/LinkOrgs-software/LinkOrgs')\n")
249
- return(invisible(FALSE))
250
- }
251
- # Try silent backend initialization
252
- ok <- TRUE
253
- try({
254
- capture.output({
255
- LinkOrgs::BuildBackend(conda = ifelse(isTRUE(nzchar(conda_arg)), conda_arg, "auto"))
256
- }, file = NULL)
257
- }, silent = TRUE) -> res
258
- if (inherits(res, "try-error")) ok <- FALSE
259
- if (ok) {
260
- backend_ready(TRUE)
261
- notify("Backend initialized—requires internet for model download.", "message", 6)
262
- } else {
263
- backend_ready(FALSE)
264
- notify("Backend setup failed—check internet or conda path. You can retry.", "error", 10)
265
- }
266
- invisible(ok)
267
- }
268
-
269
- # Attempt at startup if enabled
270
- observeEvent(TRUE, {
271
- if (isTRUE(input$run_backend_on_start)) {
272
- safe_build_backend(input$conda_path)
273
- }
274
- }, once = TRUE)
275
-
276
- # Retry backend manually
277
- observeEvent(input$retry_backend, {
278
- safe_build_backend(input$conda_path)
279
- })
280
-
281
  # Reactive: parse CSV or text input ------------------------------------------
282
  raw_input <- reactive({
283
  mode <- input$input_mode
@@ -393,10 +368,6 @@ server <- function(input, output, session) {
393
  validate(need(nrow(df) > 0, "Please provide at least one valid name."))
394
 
395
  incProgress(0.20, detail = "Initializing model...")
396
- # Ensure backend is available (attempt if not already)
397
- if (!backend_ready()) {
398
- safe_build_backend(input$conda_path)
399
- }
400
 
401
  incProgress(0.50, detail = "Calling LinkOrgs (ML embeddings)...")
402
  if (!requireNamespace("LinkOrgs", quietly = TRUE)) {
 
29
  library(shinyWidgets)
30
  })
31
 
32
+ # Lock reticulate to the prebuilt Conda env (works even on HF Spaces)
33
+ try({
34
+ conda_bin <- Sys.getenv("CONDA_EXE", Sys.which("conda"))
35
+ if (nzchar(conda_bin) && file.exists(conda_bin)) {
36
+ reticulate::use_condaenv("LinkOrgs_env", conda = conda_bin, required = TRUE)
37
+ } else if (nzchar(Sys.getenv("RETICULATE_PYTHON"))) {
38
+ reticulate::use_python(Sys.getenv("RETICULATE_PYTHON"), required = TRUE)
39
+ }
40
+ cat("[reticulate] python:", reticulate::py_config()$python, "\n")
41
+ }, silent = TRUE)
42
+
43
+
44
  # Optional tooltips (if bsplus is available)
45
  has_bsplus <- requireNamespace("bsplus", quietly = TRUE)
46
  if (has_bsplus) {
 
253
  updateTextAreaInput(session, "text_names", value = "Google\nAlphabet Inc.\nMicrosoft\nMeta Platforms\nOpenAI")
254
  })
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  # Reactive: parse CSV or text input ------------------------------------------
257
  raw_input <- reactive({
258
  mode <- input$input_mode
 
368
  validate(need(nrow(df) > 0, "Please provide at least one valid name."))
369
 
370
  incProgress(0.20, detail = "Initializing model...")
 
 
 
 
371
 
372
  incProgress(0.50, detail = "Calling LinkOrgs (ML embeddings)...")
373
  if (!requireNamespace("LinkOrgs", quietly = TRUE)) {