Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -163,27 +163,27 @@ app_css <- "
|
|
| 163 |
|
| 164 |
|
| 165 |
download_private_rds <- function(repo_id, filename) {
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
}
|
| 188 |
|
| 189 |
stuffplus_recipe <- download_private_rds("CoastalBaseball/PitcherAppFiles", "stuffplus_recipe.rds")
|
|
|
|
| 163 |
|
| 164 |
|
| 165 |
download_private_rds <- function(repo_id, filename) {
|
| 166 |
+
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
|
| 167 |
+
|
| 168 |
+
api_key <- Sys.getenv("HFToken")
|
| 169 |
+
|
| 170 |
+
if (api_key == "") {
|
| 171 |
+
stop("API key is not set.")
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
response <- GET(url, add_headers(Authorization = paste("Bearer", api_key)))
|
| 175 |
+
|
| 176 |
+
if (status_code(response) == 200) {
|
| 177 |
+
temp_file <- tempfile(fileext = ".rds")
|
| 178 |
+
|
| 179 |
+
writeBin(content(response, "raw"), temp_file)
|
| 180 |
+
|
| 181 |
+
data <- readRDS(temp_file)
|
| 182 |
+
|
| 183 |
+
return(data)
|
| 184 |
+
} else {
|
| 185 |
+
stop(paste("Failed to download dataset. Status code:", status_code(response)))
|
| 186 |
+
}
|
| 187 |
}
|
| 188 |
|
| 189 |
stuffplus_recipe <- download_private_rds("CoastalBaseball/PitcherAppFiles", "stuffplus_recipe.rds")
|