Skip to content

Commit

Permalink
added support to supply HF_API_KEY by .env file or Env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bodaay committed Jul 19, 2023
1 parent b8c68f2 commit 09639cc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
output/
Models/
Storage/
Storage/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Storage path (optional) (default "Storage")
Number of LFS concurrent connections (optional) (default 5)

`-t, --token string`
HuggingFace Access Token, required for some Models/Datasets, you still need to manually accept agreement on HuggingFace if model requires it,No bypass going to be implented (optional)
HuggingFace Access Token, this can be automatically supplied by env variable 'HF_API_KEY' or .env file (recommended), required for some Models/Datasets, you still need to manually accept agreement if model requires it (optional)

`-i, --install bool`
Install the binary to the OS default bin folder (if installPath not specified), Unix-like operating systems only
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.5
1.2.6
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"log"
"os"

"github.com/joho/godotenv"
"github.com/spf13/cobra"
)

const VERSION = "1.2.5"
const VERSION = "1.2.6"

func main() {
var (
Expand Down Expand Up @@ -73,6 +74,13 @@ func main() {
IsDataset = true
ModelOrDataSet = datasetName
}

_ = godotenv.Load() //this will give an error of the file is not there, but we dont really care

// Fetch token from command line flag or from .env file if not provided in flag
if HuggingFaceAccessToken == "" {
HuggingFaceAccessToken = os.Getenv("HF_API_KEY")
}
fmt.Println("Branch:", branch)
fmt.Println("Storage:", storage)
fmt.Println("NumberOfConcurrentConnections:", numberOfConcurrentConnections)
Expand Down Expand Up @@ -105,7 +113,7 @@ func main() {

rootCmd.Flags().IntVarP(&numberOfConcurrentConnections, "concurrent", "c", 5, "Number of LFS concurrent connections (optional)")

rootCmd.Flags().StringVarP(&HuggingFaceAccessToken, "token", "t", "", "HuggingFace Access Token, required for some Models/Datasets, you still need to manually accept agreement if model requires it (optional)")
rootCmd.Flags().StringVarP(&HuggingFaceAccessToken, "token", "t", "", "HuggingFace Access Token, this can be automatically supplied by env variable 'HF_API_KEY' or .env file, required for some Models/Datasets, you still need to manually accept agreement if model requires it (optional)")

rootCmd.Flags().BoolVarP(&install, "install", "i", false, "Install the binary to the OS default bin folder, Unix-like operating systems only")

Expand Down

0 comments on commit 09639cc

Please sign in to comment.