Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -1999,31 +1999,32 @@ observeEvent(input$upload_hf_btn, {
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
-
|
| 2003 |
-
|
|
|
|
|
|
|
| 2004 |
|
| 2005 |
-
|
| 2006 |
-
|
| 2007 |
-
|
| 2008 |
-
filename, filename, file_b64
|
| 2009 |
)
|
| 2010 |
|
| 2011 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2012 |
paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main"),
|
| 2013 |
-
|
| 2014 |
-
Authorization = paste("Bearer", hf_token),
|
| 2015 |
-
`Content-Type` = "application/json"
|
| 2016 |
-
),
|
| 2017 |
-
body = json_body,
|
| 2018 |
-
encode = "raw"
|
| 2019 |
)
|
| 2020 |
|
| 2021 |
-
resp_text <-
|
| 2022 |
|
| 2023 |
-
if (
|
| 2024 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2025 |
} else {
|
| 2026 |
-
paste0("Upload failed: ",
|
| 2027 |
}
|
| 2028 |
}, error = function(e) {
|
| 2029 |
paste("Upload error:", e$message)
|
|
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
+
header_json <- sprintf(
|
| 2003 |
+
'{"summary":"Update %s","operations":[{"key":"file0","path_in_repo":"%s"}]}',
|
| 2004 |
+
filename, filename
|
| 2005 |
+
)
|
| 2006 |
|
| 2007 |
+
h <- curl::new_handle()
|
| 2008 |
+
curl::handle_setheaders(h,
|
| 2009 |
+
"Authorization" = paste("Bearer", hf_token)
|
|
|
|
| 2010 |
)
|
| 2011 |
|
| 2012 |
+
curl::handle_setform(h,
|
| 2013 |
+
header = curl::form_data(header_json, type = "application/json"),
|
| 2014 |
+
file0 = curl::form_file(tmp, type = "application/octet-stream")
|
| 2015 |
+
)
|
| 2016 |
+
|
| 2017 |
+
resp <- curl::curl_fetch_memory(
|
| 2018 |
paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main"),
|
| 2019 |
+
handle = h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2020 |
)
|
| 2021 |
|
| 2022 |
+
resp_text <- rawToChar(resp$content)
|
| 2023 |
|
| 2024 |
+
if (resp$status_code %in% c(200, 201)) {
|
| 2025 |
paste0("Done! ", nrow(combined), " total rows in dataset.")
|
| 2026 |
} else {
|
| 2027 |
+
paste0("Upload failed: ", resp$status_code, " - ", resp_text)
|
| 2028 |
}
|
| 2029 |
}, error = function(e) {
|
| 2030 |
paste("Upload error:", e$message)
|