Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -1999,28 +1999,25 @@ observeEvent(input$upload_hf_btn, {
|
|
| 1999 |
arrow::write_parquet(combined, tmp)
|
| 2000 |
|
| 2001 |
result <- tryCatch({
|
| 2002 |
-
|
| 2003 |
-
|
| 2004 |
-
|
| 2005 |
-
|
| 2006 |
-
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
| 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)) {
|