OwenStOnge commited on
Commit
c1098e4
·
verified ·
1 Parent(s): f443c8c

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +17 -16
app.R CHANGED
@@ -1999,31 +1999,32 @@ observeEvent(input$upload_hf_btn, {
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
- # Build JSON manually to avoid serialization issues
2006
- json_body <- sprintf(
2007
- '{"summary":"Update %s","operations":[{"operation":"upload","path_in_repo":"%s","encoding":"base64","content":"%s"}]}',
2008
- filename, filename, file_b64
2009
  )
2010
 
2011
- resp <- httr::POST(
 
 
 
 
 
2012
  paste0("https://huggingface.co/api/datasets/", repo_id, "/commit/main"),
2013
- httr::add_headers(
2014
- Authorization = paste("Bearer", hf_token),
2015
- `Content-Type` = "application/json"
2016
- ),
2017
- body = json_body,
2018
- encode = "raw"
2019
  )
2020
 
2021
- resp_text <- httr::content(resp, as = "text", encoding = "UTF-8")
2022
 
2023
- if (httr::status_code(resp) %in% c(200, 201)) {
2024
  paste0("Done! ", nrow(combined), " total rows in dataset.")
2025
  } else {
2026
- paste0("Upload failed: ", httr::status_code(resp), " - ", resp_text)
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)