VeenaLim commited on
Commit
8e77f9c
·
verified ·
1 Parent(s): 9ac6d97

Delete api/plumber_hf.R

Browse files
Files changed (1) hide show
  1. api/plumber_hf.R +0 -80
api/plumber_hf.R DELETED
@@ -1,80 +0,0 @@
1
- library(dampack)
2
- library(readr)
3
- library(assertthat)
4
-
5
- #* @apiTitle DARTH Health Economic Model API
6
- #*
7
- #* @apiDescription This API runs a health economic Markov model (Sick-Sicker)
8
- #* for probabilistic sensitivity analysis. Hosted on Hugging Face Spaces.
9
-
10
- #* Health check endpoint
11
- #* @get /health
12
- function() {
13
- list(status = "healthy", timestamp = Sys.time())
14
- }
15
-
16
- #* Run the DARTH model
17
- #* @serializer csv
18
- #* @param param_updates gives the replacement values of the editable parameters (JSON string)
19
- #* @post /runDARTHmodel
20
- function(param_updates = NULL) {
21
-
22
- # Source the model functions from local file or GitHub
23
- model_functions_path <- "/app/model/darth_funcs.R"
24
- if (file.exists(model_functions_path)) {
25
- source(model_functions_path)
26
- } else {
27
- # Fallback to GitHub if local file not found
28
- source(paste0("https://raw.githubusercontent.com/",
29
- "BresMed/plumberHE/main/R/darth_funcs.R"))
30
- }
31
-
32
- # Read in the CSV containing parameter inputs
33
- psa_inputs_path <- "/app/parameter_distributions.csv"
34
- if (!file.exists(psa_inputs_path)) {
35
- psa_inputs_path <- "parameter_distributions.csv"
36
- }
37
- psa_inputs <- as.data.frame(readr::read_csv(psa_inputs_path))
38
-
39
- # Parse param_updates if provided
40
- if (!is.null(param_updates) && param_updates != "") {
41
- # Handle both JSON string and data frame input
42
- if (is.character(param_updates)) {
43
- param_updates <- jsonlite::fromJSON(param_updates)
44
- }
45
-
46
- # Convert to data frame if needed
47
- if (!is.data.frame(param_updates)) {
48
- param_updates <- as.data.frame(param_updates)
49
- }
50
-
51
- # For each row of the data-frame containing the variables to be changed...
52
- for(n in 1:nrow(param_updates)) {
53
- # Update parameters from API input
54
- psa_inputs <- overwrite_parameter_value(
55
- existing_df = psa_inputs,
56
- parameter = param_updates[n, "parameter"],
57
- distribution = param_updates[n, "distribution"],
58
- v1 = param_updates[n, "v1"],
59
- v2 = param_updates[n, "v2"]
60
- )
61
- }
62
- }
63
-
64
- # Run the model using the single run-model function
65
- results <- run_model(psa_inputs)
66
-
67
- # Check that the model results being returned are the correct dimensions
68
- assertthat::assert_that(
69
- all(dim(x = results) == c(1000, 6)),
70
- class(results) == "data.frame",
71
- msg = "Dimensions or type of data are incorrect, please check the model code."
72
- )
73
-
74
- # Check that no sensitive data is included in the output
75
- assertthat::assert_that(
76
- all(psa_inputs[, 1] %in% as.character(unlist(x = results, recursive = TRUE)) == FALSE)
77
- )
78
-
79
- return(results)
80
- }