Spaces:
Sleeping
Sleeping
Create download_data.R
Browse files- download_data.R +33 -0
download_data.R
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(httr)
|
| 2 |
+
|
| 3 |
+
token <- Sys.getenv("HF_TOKEN")
|
| 4 |
+
repo <- "BU-Baseball/butler-baseball-data"
|
| 5 |
+
base_url <- paste0("https://huggingface.co/datasets/", repo, "/resolve/main/")
|
| 6 |
+
|
| 7 |
+
download_hf <- function(filename) {
|
| 8 |
+
dest <- paste0("/app/", filename)
|
| 9 |
+
if (file.exists(dest)) {
|
| 10 |
+
message(filename, " already exists, skipping.")
|
| 11 |
+
return(invisible(NULL))
|
| 12 |
+
}
|
| 13 |
+
message("Downloading ", filename, "...")
|
| 14 |
+
resp <- GET(
|
| 15 |
+
paste0(base_url, filename),
|
| 16 |
+
add_headers(Authorization = paste("Bearer", token)),
|
| 17 |
+
write_disk(dest, overwrite = TRUE),
|
| 18 |
+
progress()
|
| 19 |
+
)
|
| 20 |
+
if (status_code(resp) != 200)
|
| 21 |
+
stop("Failed to download ", filename, " — status ", status_code(resp))
|
| 22 |
+
message(filename, " done.")
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
files <- c(
|
| 26 |
+
"Stuff+2.rds",
|
| 27 |
+
"NEW_LeagueStats2.rds",
|
| 28 |
+
"location_plus_model.rds",
|
| 29 |
+
"location_plus_league_stats_pitcher.rds"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
for (f in files) download_hf(f)
|
| 33 |
+
message("All model files ready.")
|