TimStats commited on
Commit
e2a31f7
·
verified ·
1 Parent(s): caefdd2

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +58 -0
app.R CHANGED
@@ -2,6 +2,64 @@ library(shiny)
2
  library(dplyr)
3
  library(ggplot2)
4
  library(utils)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  #data1 <- read.csv("data1.csv", header = TRUE, check.names = FALSE, fileEncoding = "UTF-8")
7
  #data1 <- data1[,2:54]
 
2
  library(dplyr)
3
  library(ggplot2)
4
  library(utils)
5
+ library(httr)
6
+
7
+ download_private_csv <- function(repo_id, filename) {
8
+ url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
9
+ response <- GET(url, add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))))
10
+
11
+ if (status_code(response) == 200) {
12
+ # Get content as text first to check if it's an LFS pointer
13
+ content_text <- content(response, "text", encoding = "UTF-8")
14
+
15
+ # Check if this is an LFS pointer (LFS files start with "version https://git-lfs.github.com/spec/")
16
+ if (grepl("^version https://git-lfs.github.com/spec/", content_text)) {
17
+ # This is an LFS file - extract the oid (hash) from the pointer
18
+ oid_line <- grep("oid sha256:", strsplit(content_text, "\n")[[1]], value = TRUE)
19
+ oid <- gsub("oid sha256:", "", oid_line)
20
+ oid <- trimws(oid)
21
+
22
+ # Construct the LFS content URL
23
+ lfs_url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/.git/lfs/objects/",
24
+ substr(oid, 1, 2), "/", substr(oid, 3, 4), "/", oid)
25
+
26
+ # Get the actual content from LFS storage
27
+ lfs_response <- GET(lfs_url, add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))))
28
+
29
+ if (status_code(lfs_response) == 200) {
30
+ content_text <- content(lfs_response, "text", encoding = "UTF-8")
31
+ } else {
32
+ # Alternative LFS URL format
33
+ lfs_url <- paste0("https://huggingface.co/datasets/", repo_id, "/lfs/resolve/main/", filename, "?download=true")
34
+ lfs_response <- GET(lfs_url, add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))))
35
+
36
+ if (status_code(lfs_response) == 200) {
37
+ content_text <- content(lfs_response, "text", encoding = "UTF-8")
38
+ } else {
39
+ stop(paste("Failed to download LFS content. Status code:", status_code(lfs_response)))
40
+ }
41
+ }
42
+ }
43
+
44
+ # Process the content (whether it was LFS or regular)
45
+ con <- textConnection(content_text)
46
+ tryCatch({
47
+ data <- read.csv(con,
48
+ header = TRUE,
49
+ check.names = FALSE,
50
+ fileEncoding = "UTF-8",
51
+ stringsAsFactors = FALSE)
52
+ return(data)
53
+ }, error = function(e) {
54
+ close(con)
55
+ stop(paste("Error parsing CSV:", e$message))
56
+ }, finally = {
57
+ close(con)
58
+ })
59
+ } else {
60
+ stop(paste("Failed to download dataset. Status code:", status_code(response)))
61
+ }
62
+ }
63
 
64
  #data1 <- read.csv("data1.csv", header = TRUE, check.names = FALSE, fileEncoding = "UTF-8")
65
  #data1 <- data1[,2:54]