Spaces:
Sleeping
Sleeping
Download run_equil2_cli.R from riki74/equil2-api: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/riki74/equil2-api/resolve/main/run_equil2_cli.R
- Command line
-
hf download hf://spaces/riki74/equil2-api/run_equil2_cli.R
-
curl -L -o run_equil2_cli.R https://huggingface.co/spaces/riki74/equil2-api/resolve/main/run_equil2_cli.R
1.17 kB
| #!/usr/bin/env Rscript | |
| args <- commandArgs(trailingOnly = TRUE) | |
| if (length(args) < 1) { | |
| cat("EQUIL2 CLI - Batch Urinary Supersaturation Calculator\n") | |
| cat("Usage: Rscript run_equil2_cli.R input.csv [output.csv]\n") | |
| quit(status = 1) | |
| } | |
| suppressPackageStartupMessages({ | |
| library(readr) | |
| library(jsonlite) | |
| library(dplyr) | |
| }) | |
| source("helpers.R") | |
| input_file <- args[1] | |
| if (!file.exists(input_file)) { | |
| cat("Error: Input file not found.\n") | |
| quit(status = 1) | |
| } | |
| output_file <- if (length(args) >= 2) args[2] else NULL | |
| output_to_csv <- !is.null(output_file) && grepl("\\.csv$", output_file, ignore.case = TRUE) | |
| tryCatch({ | |
| df_input <- readr::read_csv(input_file, show_col_types = FALSE) | |
| df_converted <- convert_and_validate(df_input) | |
| results <- run_equil2_dataframe(df_converted) | |
| if (output_to_csv) { | |
| output_df <- as.data.frame(results$records) | |
| readr::write_csv(output_df, output_file) | |
| cat("Results written to:", output_file, "\n") | |
| } else { | |
| json_output <- jsonlite::toJSON(results, auto_unbox = TRUE, pretty = TRUE) | |
| cat(json_output) | |
| } | |
| }, error = function(e) { | |
| cat("Error:", conditionMessage(e), "\n") | |
| quit(status = 1) | |
| }) | |