Skip to content

Commit

Permalink
Simplify model download filename (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
teelisyys committed Sep 29, 2022
1 parent c62e288 commit 5a7ce7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
50 changes: 22 additions & 28 deletions cmd/download.go
Expand Up @@ -160,44 +160,38 @@ func downloadCurrentModel(ctx context.Context, absPath string, appId string, mod
}

var (
buf []byte
bundleId string
out string
skipWrite bool
buf []byte
out string
)

for {
pkg, err := stream.Recv()
if err == io.EOF {
break
}
if status.Code(err) == codes.PermissionDenied {
return false
}
if err != nil {
log.Fatalf("model fetch failed out file: %s", err)
out = filepath.Join(absPath, fmt.Sprintf("%s.%s.bundle", appId, model))
_, err = os.Stat(out)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Fatalf("Failed to verify out file %s: %s", absPath, err)
}
buf = append(buf, pkg.Chunk...)
if len(buf) > 512+28+36 {
bundleId = string(buf[512+28 : 512+28+36])
out = filepath.Join(absPath, fmt.Sprintf("%s--%s.%s.bundle", appId, bundleId, model))
_, err = os.Stat(out)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Fatalf("Failed to verify out file %s: %s", absPath, err)
}
} else {
log.Printf("File %s exists, skipping\n", out)
skipWrite = true

for {
pkg, err := stream.Recv()
if err == io.EOF {
break
}
if status.Code(err) == codes.PermissionDenied {
return false
}
if err != nil {
log.Fatalf("model fetch failed out file: %s", err)
}
buf = append(buf, pkg.Chunk...)
}
}
if !skipWrite {

log.Printf("Writing file %s (%d bytes)\n", out, len(buf))
if err := os.WriteFile(out, buf, 0644); err != nil {
log.Fatalf("Could not write configuration to %s: %s", out, err)
}

} else {
log.Printf("File %s exists, skipping\n", out)
}

return true
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -27,12 +27,12 @@ Speechly CLI
* [speechly delete](speechly_delete.md) - Delete an existing application
* [speechly deploy](speechly_deploy.md) - Send the contents of a local directory to training
* [speechly describe](speechly_describe.md) - Print details about an application
* [speechly download](speechly_download.md) - Download the active configuration or model of the given app.
* [speechly edit](speechly_edit.md) - Edit an existing application
* [speechly evaluate](speechly_evaluate.md) - Compute accuracy between annotated examples (given by 'speechly annotate') and ground truth.
* [speechly list](speechly_list.md) - List applications in the current project
* [speechly projects](speechly_projects.md) - Manage API access to Speechly projects
* [speechly sample](speechly_sample.md) - Sample a set of examples from the given SAL configuration
* [speechly speechly](speechly_speechly.md) - Download the active configuration or model of the given app.
* [speechly stats](speechly_stats.md) - Get utterance statistics for the current project or an application in it
* [speechly transcribe](speechly_transcribe.md) - Transcribe the given jsonlines file
* [speechly utterances](speechly_utterances.md) - Get a sample of recent utterances.
Expand Down
2 changes: 1 addition & 1 deletion docs/speechly.md
Expand Up @@ -27,12 +27,12 @@ Speechly CLI
* [speechly delete](speechly_delete.md) - Delete an existing application
* [speechly deploy](speechly_deploy.md) - Send the contents of a local directory to training
* [speechly describe](speechly_describe.md) - Print details about an application
* [speechly download](speechly_download.md) - Download the active configuration or model of the given app.
* [speechly edit](speechly_edit.md) - Edit an existing application
* [speechly evaluate](speechly_evaluate.md) - Compute accuracy between annotated examples (given by 'speechly annotate') and ground truth.
* [speechly list](speechly_list.md) - List applications in the current project
* [speechly projects](speechly_projects.md) - Manage API access to Speechly projects
* [speechly sample](speechly_sample.md) - Sample a set of examples from the given SAL configuration
* [speechly speechly](speechly_speechly.md) - Download the active configuration or model of the given app.
* [speechly stats](speechly_stats.md) - Get utterance statistics for the current project or an application in it
* [speechly transcribe](speechly_transcribe.md) - Transcribe the given jsonlines file
* [speechly utterances](speechly_utterances.md) - Get a sample of recent utterances.
Expand Down
12 changes: 6 additions & 6 deletions docs/speechly_download.md
@@ -1,12 +1,10 @@
## speechly download

Download the active configuration of the given app.
Download the active configuration or model of the given app.

### Synopsis

Fetches the currently stored configuration from the API. This command
does not check for validity of the stored configuration, but downloads the latest
version.
Fetches the currently stored configuration or model. This command does not check for validity of the stored configuration, but downloads the latest version.

```
speechly download [<app_id>] <directory> [flags]
Expand All @@ -17,13 +15,15 @@ speechly download [<app_id>] <directory> [flags]
```
speechly download <app_id> /path/to/config
speechly download -a <app_id> .
speechly download -a <app_id> . --model tflite
```

### Options

```
-a, --app string Which application's configuration to download. Can be given as the first positional argument.
-h, --help help for download
-a, --app string Which application's configuration or model to download. Can be given as the first positional argument.
-h, --help help for download
--model string Specify the machine learning framework of the model to download. Available options are: ort, tflite, coreml and all. This feature is available on Enterprise plans (https://speechly.com/pricing)
```

### SEE ALSO
Expand Down

0 comments on commit 5a7ce7a

Please sign in to comment.