OwenStOnge commited on
Commit
4fe7a23
·
verified ·
1 Parent(s): a21c791

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +11 -14
app.R CHANGED
@@ -1999,28 +1999,25 @@ observeEvent(input$upload_hf_btn, {
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)) {
 
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","content_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)) {