Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -1999,29 +1999,34 @@ observeEvent(input$upload_hf_btn, {
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
|
|
|
| 2002 |
header_file <- tempfile(fileext = ".json")
|
| 2003 |
-
|
| 2004 |
'{"summary":"Update ', filename, '",',
|
| 2005 |
'"operations":[{"key":"file","path_in_repo":"', filename, '"}]}'
|
| 2006 |
-
)
|
|
|
|
| 2007 |
|
| 2008 |
-
resp <-
|
| 2009 |
-
"
|
| 2010 |
-
|
| 2011 |
-
|
| 2012 |
-
|
| 2013 |
-
|
| 2014 |
-
|
| 2015 |
-
|
|
|
|
|
|
|
|
|
|
| 2016 |
|
| 2017 |
file.remove(header_file)
|
| 2018 |
|
| 2019 |
-
resp_text <-
|
| 2020 |
|
| 2021 |
-
if (
|
| 2022 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2023 |
} else {
|
| 2024 |
-
paste0("Upload
|
| 2025 |
}
|
| 2026 |
}, error = function(e) {
|
| 2027 |
paste("Upload error:", e$message)
|
|
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
+
# Write the header JSON to a temp file
|
| 2003 |
header_file <- tempfile(fileext = ".json")
|
| 2004 |
+
header_json <- paste0(
|
| 2005 |
'{"summary":"Update ', filename, '",',
|
| 2006 |
'"operations":[{"key":"file","path_in_repo":"', filename, '"}]}'
|
| 2007 |
+
)
|
| 2008 |
+
writeBin(charToRaw(header_json), header_file)
|
| 2009 |
|
| 2010 |
+
resp <- httr::POST(
|
| 2011 |
+
paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main"),
|
| 2012 |
+
httr::add_headers(
|
| 2013 |
+
Authorization = paste("Bearer", hf_token)
|
| 2014 |
+
),
|
| 2015 |
+
body = list(
|
| 2016 |
+
header = httr::upload_file(header_file, type = "application/json"),
|
| 2017 |
+
file = httr::upload_file(tmp, type = "application/octet-stream")
|
| 2018 |
+
),
|
| 2019 |
+
encode = "multipart"
|
| 2020 |
+
)
|
| 2021 |
|
| 2022 |
file.remove(header_file)
|
| 2023 |
|
| 2024 |
+
resp_text <- httr::content(resp, as = "text", encoding = "UTF-8")
|
| 2025 |
|
| 2026 |
+
if (httr::status_code(resp) %in% c(200, 201)) {
|
| 2027 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2028 |
} else {
|
| 2029 |
+
paste0("Upload failed: ", httr::status_code(resp), " - ", resp_text)
|
| 2030 |
}
|
| 2031 |
}, error = function(e) {
|
| 2032 |
paste("Upload error:", e$message)
|