OwenStOnge commited on
Commit
e8c48d8
·
verified ·
1 Parent(s): bad9e49

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +22 -30
app.R CHANGED
@@ -1998,38 +1998,30 @@ observeEvent(input$upload_hf_btn, {
1998
  tmp <- tempfile(fileext = ".parquet")
1999
  arrow::write_parquet(combined, tmp)
2000
 
2001
- result <- tryCatch({
2002
- file_bytes <- readBin(tmp, "raw", file.info(tmp)$size)
2003
- file_b64 <- base64enc::base64encode(file_bytes)
2004
-
2005
- body <- list(
2006
- summary = paste("Update", filename),
2007
- commit_message = paste("Update", filename),
2008
- operations = I(list(
2009
- list(
2010
- operation = "upload",
2011
- path_in_repo = filename,
2012
- content_encoding = "base64",
2013
- content = file_b64
2014
- )
2015
- ))
2016
- )
2017
-
2018
- resp <- httr::POST(
2019
- paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main"),
2020
- httr::add_headers(
2021
- Authorization = paste("Bearer", hf_token),
2022
- `Content-Type` = "application/json"
2023
- ),
2024
- body = jsonlite::toJSON(body, auto_unbox = TRUE),
2025
- encode = "raw"
2026
- )
2027
-
2028
- if (httr::status_code(resp) %in% c(200, 201)) {
2029
  paste0("Done! ", nrow(combined), " total rows in dataset.")
2030
  } else {
2031
- resp_text <- httr::content(resp, as = "text", encoding = "UTF-8")
2032
- paste0("Upload failed: ", httr::status_code(resp), " - ", resp_text)
2033
  }
2034
  }, error = function(e) {
2035
  paste("Upload error:", e$message)
 
1998
  tmp <- tempfile(fileext = ".parquet")
1999
  arrow::write_parquet(combined, tmp)
2000
 
2001
+ result <- tryCatch({
2002
+ header_file <- tempfile(fileext = ".json")
2003
+ writeLines(paste0(
2004
+ '{"summary":"Update ', filename, '",',
2005
+ '"operations":[{"key":"file","path_in_repo":"', filename, '"}]}'
2006
+ ), header_file)
2007
+
2008
+ resp <- system2("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('file=@', 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
+
2019
+ resp_text <- paste(resp, collapse = "\n")
2020
+
2021
+ if (grepl("commitOid", resp_text)) {
 
 
 
 
 
 
 
2022
  paste0("Done! ", nrow(combined), " total rows in dataset.")
2023
  } else {
2024
+ paste0("Upload response: ", resp_text)
 
2025
  }
2026
  }, error = function(e) {
2027
  paste("Upload error:", e$message)