TimStats commited on
Commit
cdc7067
·
verified ·
1 Parent(s): 93e5a84

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +38 -3
app.R CHANGED
@@ -27,9 +27,44 @@ download_private_csv <- function(repo_id, filename) {
27
  stop("Failed to download dataset")
28
  }
29
  }
30
- MLB <- download_private_csv("TimStats/StatcastDataAll", "MLB.csv") %>% filter(season == 2024)
31
- AAA <- download_private_csv("TimStats/StatcastDataAll", "AAA.csv") %>% filter(season == 2024)
32
- FSL <- download_private_csv("TimStats/StatcastDataAll", "FSL.csv") %>% filter(season == 2024)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
 
35
  MLB <- MLB %>%
 
27
  stop("Failed to download dataset")
28
  }
29
  }
30
+ download_private_parquet <- function(repo_id, filename) {
31
+ library(httr)
32
+ library(arrow)
33
+
34
+ # Create the direct download URL based on your example
35
+ url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename, "?download=true")
36
+
37
+ # Create a temporary file
38
+ temp_file <- tempfile(fileext = ".parquet")
39
+
40
+ # Download directly to file
41
+ response <- GET(
42
+ url,
43
+ add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))),
44
+ write_disk(temp_file, overwrite = TRUE)
45
+ )
46
+
47
+ # Check if download was successful
48
+ if (status_code(response) == 200) {
49
+ tryCatch({
50
+ # Read the parquet file
51
+ data <- read_parquet(temp_file)
52
+ file.remove(temp_file)
53
+ return(data)
54
+ }, error = function(e) {
55
+ file.remove(temp_file)
56
+ stop(paste("Error reading parquet file:", e$message))
57
+ })
58
+ } else {
59
+ file.remove(temp_file)
60
+ stop(paste("Failed to download file. Status code:", status_code(response)))
61
+ }
62
+ }
63
+
64
+
65
+ MLB <- download_private_parquet("TimStats/StatcastDataAll", "MLB25.parquet")
66
+ AAA <- download_private_parquet("TimStats/StatcastDataAll", "AAA25.parquet")
67
+ FSL <- download_private_parquet("TimStats/StatcastDataAll", "FSL25.parquet")
68
 
69
 
70
  MLB <- MLB %>%