OwenStOnge commited on
Commit
a3e2045
·
verified ·
1 Parent(s): 0a047ab

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +22 -5
app.R CHANGED
@@ -13,6 +13,7 @@ library(curl)
13
  library(xgboost)
14
  library(recipes)
15
  library(arrow)
 
16
 
17
  rv <- read_csv("non_context_run_values.csv")
18
  stuffplus_model <- xgb.load("stuffplus_xgb.json")
@@ -1992,20 +1993,36 @@ observeEvent(input$upload_hf_btn, {
1992
  combined <- scraped_data()
1993
  }
1994
 
1995
- # Upload combined data as parquet
1996
  scrape_status_msg(paste0("Uploading ", nrow(combined), " total rows..."))
1997
 
1998
  tmp <- tempfile(fileext = ".parquet")
1999
  arrow::write_parquet(combined, tmp)
2000
 
2001
  result <- tryCatch({
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2002
  resp <- httr::POST(
2003
- paste0("https://huggingface.co/api/datasets/", repo_id, "/upload/main/", filename),
2004
  httr::add_headers(
2005
- Authorization = paste("Bearer", hf_token)
 
2006
  ),
2007
- body = list(file = httr::upload_file(tmp)),
2008
- encode = "multipart"
2009
  )
2010
 
2011
  if (httr::status_code(resp) %in% c(200, 201)) {
 
13
  library(xgboost)
14
  library(recipes)
15
  library(arrow)
16
+ library(base64enc)
17
 
18
  rv <- read_csv("non_context_run_values.csv")
19
  stuffplus_model <- xgb.load("stuffplus_xgb.json")
 
1993
  combined <- scraped_data()
1994
  }
1995
 
1996
+ # Upload via commit API
1997
  scrape_status_msg(paste0("Uploading ", nrow(combined), " total rows..."))
1998
 
1999
  tmp <- tempfile(fileext = ".parquet")
2000
  arrow::write_parquet(combined, tmp)
2001
 
2002
  result <- tryCatch({
2003
+ file_bytes <- readBin(tmp, "raw", file.info(tmp)$size)
2004
+ file_b64 <- base64enc::base64encode(file_bytes)
2005
+
2006
+ body <- list(
2007
+ commit_message = paste("Update", filename),
2008
+ operations = 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)) {