Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -1999,56 +1999,29 @@ observeEvent(input$upload_hf_btn, {
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
-
|
| 2003 |
-
|
| 2004 |
-
|
| 2005 |
-
|
| 2006 |
-
|
| 2007 |
-
|
| 2008 |
-
|
| 2009 |
-
|
| 2010 |
-
|
| 2011 |
-
|
| 2012 |
-
|
| 2013 |
-
|
| 2014 |
-
|
| 2015 |
-
),
|
| 2016 |
-
|
| 2017 |
-
|
| 2018 |
-
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
`Content-Type` = "application/json"
|
| 2022 |
-
),
|
| 2023 |
-
body = body,
|
| 2024 |
-
encode = "raw"
|
| 2025 |
-
)
|
| 2026 |
-
|
| 2027 |
-
resp_text <- httr::content(resp, as = "text", encoding = "UTF-8")
|
| 2028 |
-
|
| 2029 |
-
if (httr::status_code(resp) %in% c(200, 201)) {
|
| 2030 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2031 |
} else {
|
| 2032 |
-
|
| 2033 |
-
resp2 <- httr::PUT(
|
| 2034 |
-
paste0("https://huggingface.co/api/datasets/", repo_id, "/content/main/", csv_filename),
|
| 2035 |
-
httr::add_headers(
|
| 2036 |
-
Authorization = paste("Bearer", hf_token),
|
| 2037 |
-
`Content-Type` = "application/json"
|
| 2038 |
-
),
|
| 2039 |
-
body = body,
|
| 2040 |
-
encode = "raw"
|
| 2041 |
-
)
|
| 2042 |
-
|
| 2043 |
-
resp_text2 <- httr::content(resp2, as = "text", encoding = "UTF-8")
|
| 2044 |
-
|
| 2045 |
-
if (httr::status_code(resp2) %in% c(200, 201)) {
|
| 2046 |
-
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2047 |
-
} else {
|
| 2048 |
-
paste0("Upload failed: ", httr::status_code(resp2), " - ", resp_text2)
|
| 2049 |
-
}
|
| 2050 |
}
|
| 2051 |
-
|
| 2052 |
}, error = function(e) {
|
| 2053 |
paste("Upload error:", e$message)
|
| 2054 |
})
|
|
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
+
header_file <- tempfile(fileext = ".json")
|
| 2003 |
+
cat(sprintf(
|
| 2004 |
+
'{"summary":"Update %s","operations":[{"key":"file0","path_in_repo":"%s"}]}',
|
| 2005 |
+
filename, filename
|
| 2006 |
+
), file = header_file)
|
| 2007 |
+
|
| 2008 |
+
resp <- system2("/usr/bin/curl", args = c(
|
| 2009 |
+
"-s",
|
| 2010 |
+
"-X", "POST",
|
| 2011 |
+
"-H", paste0("Authorization: Bearer ", hf_token),
|
| 2012 |
+
"-F", paste0("header=@", header_file, ";type=application/json"),
|
| 2013 |
+
"-F", paste0("file0=@", tmp, ";type=application/octet-stream"),
|
| 2014 |
+
paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main")
|
| 2015 |
+
), stdout = TRUE, stderr = TRUE)
|
| 2016 |
+
|
| 2017 |
+
file.remove(header_file)
|
| 2018 |
+
resp_text <- paste(resp, collapse = "\n")
|
| 2019 |
+
|
| 2020 |
+
if (grepl("commitOid", resp_text)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2021 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2022 |
} else {
|
| 2023 |
+
paste0("Upload response: ", resp_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2024 |
}
|
|
|
|
| 2025 |
}, error = function(e) {
|
| 2026 |
paste("Upload error:", e$message)
|
| 2027 |
})
|