func (a *ImporterArgs) RunImporterCli(_ *cli.Context) error {
	return a.RunImporter()
}
RunImporterCli runs the importer from the command line.
package internal
import (
	"fmt"
	"github.com/nlpodyssey/spago/pkg/nlp/transformers/huggingface"
	"github.com/nlpodyssey/spago/pkg/utils/homedir"
	"github.com/urfave/cli/v2"
	"log"
	"os"
	"os/user"
	"path"
	"path/filepath"
	"strings"
)
const (
	DefaultModelsURL = "https://huggingface.co/models"
	DefaultRepoPath = "~/.spago/"
	CacheFileName = "huggingface-co-cache.json"
)
type ImporterArgs struct {
	Repo      string
	Model     string
	ModelsURL string
	Overwrite bool
}
func NewImporterArgs(repo, model, modelsURL string, overwrite bool) *ImporterArgs {
	return &ImporterArgs{
		Repo:      repo,
		Model:     model,
		ModelsURL: modelsURL,
		Overwrite: overwrite,
	}
}
func NewDefaultImporterArgs() *ImporterArgs {
	return NewImporterArgs(DefaultRepoPath, "", DefaultModelsURL, false)
}
func (a *ImporterArgs) BuildFlags() []cli.Flag {
	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}
	return []cli.Flag{
		&cli.StringFlag{
			Name:        "repo",
			Value:       path.Join(usr.HomeDir, ".spago"),
			Usage:       "Directory to download the model [default: `DIR`]",
			Destination: &a.Repo,
		},
		&cli.StringFlag{
			Name:        "model",
			Usage:       "name of the model to convert",
			Value:       a.Model,
			Destination: &a.Model,
		},
		&cli.BoolFlag{
			Name:        "overwrite",
			Usage:       "overwrite files if they exist already",
			Destination: &a.Overwrite,
		},
	}
}
func (a *ImporterArgs) RunImporter() error {
	repo, err := homedir.Expand(a.Repo)
	if err != nil {
		return err
	}
	if a.Model == "" {
		if err := a.ConfigureInteractive(repo); err != nil {
			return err
		}
	}
	if _, err := os.Stat(a.Repo); os.IsNotExist(err) {
		if err := os.MkdirAll(a.Repo, 0755); err != nil {
			return err
		}
	}
	modelPath := filepath.Join(a.Repo, a.Model)
	if _, err := os.Stat(modelPath); os.IsNotExist(err) || a.Overwrite {
		fmt.Printf("Pulling `%s` from Hugging Face models hub...\n", a.Model)
		err = huggingface.NewDownloader(a.Repo, a.Model, true).Download()
		if err != nil {
			return err
		}
	}
	fmt.Printf("Converting `%s` model...\n", a.Model)
	return huggingface.NewConverter(a.Repo, a.Model).Convert()
}