Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -60,13 +60,47 @@ download_private_csv <- function(repo_id, filename) {
|
|
| 60 |
stop(paste("Failed to download dataset. Status code:", status_code(response)))
|
| 61 |
}
|
| 62 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
#data1 <- read.csv("data1.csv", header = TRUE, check.names = FALSE, fileEncoding = "UTF-8")
|
| 65 |
#data1 <- data1[,2:54]
|
| 66 |
-
MLB25 <- download_private_csv("TimStats/StatcastDataAll", "MLB25.csv")
|
| 67 |
-
MLB25$level <- "MLB"
|
| 68 |
-
MLB <- download_private_csv("TimStats/StatcastDataAll", "MLB.csv")
|
| 69 |
-
data1 <- rbind(MLB25,MLB)
|
| 70 |
|
| 71 |
AAaveragePT <- data1 %>%
|
| 72 |
mutate(arm_angle = round(arm_angle, digits = 0)) %>%
|
|
|
|
| 60 |
stop(paste("Failed to download dataset. Status code:", status_code(response)))
|
| 61 |
}
|
| 62 |
}
|
| 63 |
+
download_private_parquet <- function(repo_id, filename) {
|
| 64 |
+
library(httr)
|
| 65 |
+
library(arrow)
|
| 66 |
+
|
| 67 |
+
# Create the direct download URL based on your example
|
| 68 |
+
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename, "?download=true")
|
| 69 |
+
|
| 70 |
+
# Create a temporary file
|
| 71 |
+
temp_file <- tempfile(fileext = ".parquet")
|
| 72 |
+
|
| 73 |
+
# Download directly to file
|
| 74 |
+
response <- GET(
|
| 75 |
+
url,
|
| 76 |
+
add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))),
|
| 77 |
+
write_disk(temp_file, overwrite = TRUE)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# Check if download was successful
|
| 81 |
+
if (status_code(response) == 200) {
|
| 82 |
+
tryCatch({
|
| 83 |
+
# Read the parquet file
|
| 84 |
+
data <- read_parquet(temp_file)
|
| 85 |
+
file.remove(temp_file)
|
| 86 |
+
return(data)
|
| 87 |
+
}, error = function(e) {
|
| 88 |
+
file.remove(temp_file)
|
| 89 |
+
stop(paste("Error reading parquet file:", e$message))
|
| 90 |
+
})
|
| 91 |
+
} else {
|
| 92 |
+
file.remove(temp_file)
|
| 93 |
+
stop(paste("Failed to download file. Status code:", status_code(response)))
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
|
| 97 |
+
MLB25 <- download_private_parquet("TimStats/StatcastDataAll", "MLB25.parquet")
|
| 98 |
+
MLB25$level <- "MLB"
|
| 99 |
+
#names(ST)
|
| 100 |
+
MLB <- download_private_parquet("TimStats/StatcastDataAll", "MLB.parquet")
|
| 101 |
+
data1 <- rbind(MLB,MLB25)
|
| 102 |
#data1 <- read.csv("data1.csv", header = TRUE, check.names = FALSE, fileEncoding = "UTF-8")
|
| 103 |
#data1 <- data1[,2:54]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
AAaveragePT <- data1 %>%
|
| 106 |
mutate(arm_angle = round(arm_angle, digits = 0)) %>%
|