Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 75e9119

Browse files
committed
add model download pre-condition check
1 parent 8536118 commit 75e9119

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docs/guides/python/ai-podcast-part-1.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,13 @@ Nitric.run()
438438
Then we can add an API endpoint to trigger the download job and update the API endpoint to allow selection of models and voice presets.
439439

440440
```python title: services/api.py
441-
from common.resources import main_api, gen_audio_job, download_audio_model_job
441+
from common.resources import main_api, gen_audio_job, download_audio_model_job, models_bucket
442442
from nitric.application import Nitric
443443
from nitric.context import HttpContext
444444

445445
generate_audio = gen_audio_job.allow('submit')
446446
download_audio_model = download_audio_model_job.allow('submit')
447+
models = models_bucket.allow("read")
447448

448449
audio_model_id = "suno/bark"
449450
default_voice_preset = "v2/en_speaker_6"
@@ -467,6 +468,12 @@ async def submit_auto(ctx: HttpContext):
467468
if isinstance(model_id, list):
468469
model_id = model_id[0]
469470

471+
model_downloaded = await models.exists(f"{model_id}.zip")
472+
if not model_downloaded:
473+
ctx.res.status = 404
474+
ctx.res.body = f'model \'{model_id}\' hasn\'t been downloaded yet, call POST: /download-audio-model to pre-download the model'
475+
return
476+
470477
if isinstance(preset, list):
471478
preset = preset[0]
472479

0 commit comments

Comments
 (0)