kiapi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kiapi/__init__.py +3 -0
- kiapi/__main__.py +4 -0
- kiapi/api/__init__.py +26 -0
- kiapi/api/_constants/require_auth.py +14 -0
- kiapi/api/_helpers/build_job_responses.py +73 -0
- kiapi/api/_helpers/build_openapi.py +55 -0
- kiapi/api/_helpers/build_train_responses.py +21 -0
- kiapi/api/_helpers/get_accept.py +20 -0
- kiapi/api/_helpers/get_ctx.py +7 -0
- kiapi/api/_helpers/get_worker.py +7 -0
- kiapi/api/_helpers/register_capability_endpoints.py +70 -0
- kiapi/api/_helpers/submit_and_maybe_wait.py +113 -0
- kiapi/api/_settings.py +50 -0
- kiapi/api/_views/async_job_response.py +21 -0
- kiapi/api/_views/capability_model_spec.py +49 -0
- kiapi/api/app.py +150 -0
- kiapi/api/audio/acestep/_views/extract_response.py +57 -0
- kiapi/api/audio/acestep/_views/track_response.py +57 -0
- kiapi/api/audio/acestep/router.py +190 -0
- kiapi/api/audio/audiogen/_views/audio_response.py +46 -0
- kiapi/api/audio/audiogen/router.py +77 -0
- kiapi/api/chat/_views/chat_completion_response.py +71 -0
- kiapi/api/chat/router.py +253 -0
- kiapi/api/embedding/_views/embedding_response.py +35 -0
- kiapi/api/embedding/router.py +82 -0
- kiapi/api/files/_operations/get_file.py +14 -0
- kiapi/api/files/_operations/get_file_id.py +18 -0
- kiapi/api/files/_views/file_delete_response.py +14 -0
- kiapi/api/files/_views/file_list_response.py +15 -0
- kiapi/api/files/router.py +105 -0
- kiapi/api/health/_views/health_response.py +26 -0
- kiapi/api/health/router.py +28 -0
- kiapi/api/image/depthpro/_views/estimate_response.py +70 -0
- kiapi/api/image/depthpro/router.py +81 -0
- kiapi/api/image/ernie/_views/image_response.py +50 -0
- kiapi/api/image/ernie/router.py +181 -0
- kiapi/api/image/flux2/_views/image_response.py +53 -0
- kiapi/api/image/flux2/router.py +197 -0
- kiapi/api/image/ideogram4/_views/image_response.py +55 -0
- kiapi/api/image/ideogram4/router.py +87 -0
- kiapi/api/image/qwen/_views/image_response.py +47 -0
- kiapi/api/image/qwen/router.py +141 -0
- kiapi/api/image/seedvr2/_views/image_response.py +50 -0
- kiapi/api/image/seedvr2/router.py +83 -0
- kiapi/api/image/zimage/_views/image_response.py +49 -0
- kiapi/api/image/zimage/router.py +131 -0
- kiapi/api/jobs/_operations/get_job_id.py +18 -0
- kiapi/api/jobs/_views/job_delete_response.py +19 -0
- kiapi/api/jobs/_views/job_list_response.py +15 -0
- kiapi/api/jobs/router.py +62 -0
- kiapi/api/models/_schemas/openai_model_spec.py +26 -0
- kiapi/api/models/_views/model_list_response.py +15 -0
- kiapi/api/models/router.py +29 -0
- kiapi/api/video/ltx2/_views/__init__.py +1 -0
- kiapi/api/video/ltx2/_views/video_response.py +59 -0
- kiapi/api/video/ltx2/router.py +89 -0
- kiapi/api/web/_views/__init__.py +7 -0
- kiapi/api/web/_views/fetch_api_request.py +26 -0
- kiapi/api/web/_views/fetch_error_response.py +25 -0
- kiapi/api/web/router.py +302 -0
- kiapi/capabilities/__init__.py +24 -0
- kiapi/capabilities/_exceptions/CapabilityError.py +2 -0
- kiapi/capabilities/_exceptions/ValidationError.py +2 -0
- kiapi/capabilities/_helpers/attach_mflux_progress.py +50 -0
- kiapi/capabilities/_helpers/get_file_path.py +20 -0
- kiapi/capabilities/_helpers/resolve_file_ref.py +16 -0
- kiapi/capabilities/acestep/README.ja.md +174 -0
- kiapi/capabilities/acestep/README.md +167 -0
- kiapi/capabilities/acestep/__init__.py +37 -0
- kiapi/capabilities/acestep/_constants/description.py +122 -0
- kiapi/capabilities/acestep/_exceptions/ace_step_engine_error.py +2 -0
- kiapi/capabilities/acestep/_helpers/register.py +96 -0
- kiapi/capabilities/acestep/_models/acestep.py +105 -0
- kiapi/capabilities/acestep/_operations/handle_cover.py +23 -0
- kiapi/capabilities/acestep/_operations/handle_extract.py +38 -0
- kiapi/capabilities/acestep/_operations/handle_generate.py +18 -0
- kiapi/capabilities/acestep/_operations/handle_repaint.py +25 -0
- kiapi/capabilities/acestep/_operations/resolve_ace_step_paths.py +30 -0
- kiapi/capabilities/acestep/_operations/resolve_cover_params.py +21 -0
- kiapi/capabilities/acestep/_operations/resolve_engine.py +10 -0
- kiapi/capabilities/acestep/_operations/resolve_extract_params.py +24 -0
- kiapi/capabilities/acestep/_operations/resolve_generate_params.py +18 -0
- kiapi/capabilities/acestep/_operations/resolve_repaint_params.py +22 -0
- kiapi/capabilities/acestep/_schemas/ace_step_paths.py +29 -0
- kiapi/capabilities/acestep/_services/ace_step_engine.py +143 -0
- kiapi/capabilities/acestep/_settings.py +82 -0
- kiapi/capabilities/acestep/_views/ace_step_base.py +61 -0
- kiapi/capabilities/acestep/_views/cover_params.py +26 -0
- kiapi/capabilities/acestep/_views/cover_request.py +49 -0
- kiapi/capabilities/acestep/_views/extract_params.py +24 -0
- kiapi/capabilities/acestep/_views/extract_request.py +33 -0
- kiapi/capabilities/acestep/_views/generate_params.py +25 -0
- kiapi/capabilities/acestep/_views/generate_request.py +54 -0
- kiapi/capabilities/acestep/_views/repaint_params.py +27 -0
- kiapi/capabilities/acestep/_views/repaint_request.py +51 -0
- kiapi/capabilities/acestep/_views/track_params.py +7 -0
- kiapi/capabilities/acestep/worker_subprocess.py +247 -0
- kiapi/capabilities/audiogen/README.ja.md +49 -0
- kiapi/capabilities/audiogen/README.md +48 -0
- kiapi/capabilities/audiogen/__init__.py +25 -0
- kiapi/capabilities/audiogen/_constants/description.py +60 -0
- kiapi/capabilities/audiogen/_helpers/attach_audiogen_progress.py +27 -0
- kiapi/capabilities/audiogen/_helpers/register.py +42 -0
- kiapi/capabilities/audiogen/_helpers/validate_generate.py +14 -0
- kiapi/capabilities/audiogen/_models/audiogen.py +98 -0
- kiapi/capabilities/audiogen/_operations/handle_generate.py +27 -0
- kiapi/capabilities/audiogen/_operations/resolve_generate_params.py +25 -0
- kiapi/capabilities/audiogen/_settings.py +34 -0
- kiapi/capabilities/audiogen/_views/generate_params.py +14 -0
- kiapi/capabilities/audiogen/_views/generate_request.py +96 -0
- kiapi/capabilities/chat/README.ja.md +822 -0
- kiapi/capabilities/chat/README.md +806 -0
- kiapi/capabilities/chat/__init__.py +25 -0
- kiapi/capabilities/chat/_constants/description.py +163 -0
- kiapi/capabilities/chat/_helpers/register.py +67 -0
- kiapi/capabilities/chat/_models/qwen3_5.py +183 -0
- kiapi/capabilities/chat/_models/qwen3_omni.py +242 -0
- kiapi/capabilities/chat/_operations/apply_template.py +74 -0
- kiapi/capabilities/chat/_operations/completed_hermes_tool_call_text.py +9 -0
- kiapi/capabilities/chat/_operations/emit_streaming_response.py +297 -0
- kiapi/capabilities/chat/_operations/ensure_streaming_detokenizer_compat.py +49 -0
- kiapi/capabilities/chat/_operations/format_response.py +72 -0
- kiapi/capabilities/chat/_operations/handle_chat.py +25 -0
- kiapi/capabilities/chat/_operations/parse_hermes_tool_calls.py +63 -0
- kiapi/capabilities/chat/_operations/parse_json_tool_calls.py +66 -0
- kiapi/capabilities/chat/_operations/parse_messages.py +326 -0
- kiapi/capabilities/chat/_operations/resolve_chat_params.py +50 -0
- kiapi/capabilities/chat/_operations/stream_text_from_tokens.py +32 -0
- kiapi/capabilities/chat/_operations/strip_tool_calls.py +15 -0
- kiapi/capabilities/chat/_settings.py +74 -0
- kiapi/capabilities/chat/_utils/apply_parallel_tool_call_policy.py +17 -0
- kiapi/capabilities/chat/_utils/apply_seed.py +8 -0
- kiapi/capabilities/chat/_utils/load_audio_mono.py +31 -0
- kiapi/capabilities/chat/_utils/load_mlx_vlm.py +12 -0
- kiapi/capabilities/chat/_utils/warmup_params.py +26 -0
- kiapi/capabilities/chat/_views/chat_params.py +34 -0
- kiapi/capabilities/chat/_views/chat_request.py +153 -0
- kiapi/capabilities/depthpro/README.ja.md +131 -0
- kiapi/capabilities/depthpro/README.md +124 -0
- kiapi/capabilities/depthpro/__init__.py +23 -0
- kiapi/capabilities/depthpro/_constants/description.py +39 -0
- kiapi/capabilities/depthpro/_helpers/register.py +46 -0
- kiapi/capabilities/depthpro/_helpers/validate_estimate.py +32 -0
- kiapi/capabilities/depthpro/_models/depthpro.py +144 -0
- kiapi/capabilities/depthpro/_operations/handle_estimate.py +50 -0
- kiapi/capabilities/depthpro/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/depthpro/_operations/resolve_estimate_params.py +24 -0
- kiapi/capabilities/depthpro/_settings.py +46 -0
- kiapi/capabilities/depthpro/_views/estimate_params.py +21 -0
- kiapi/capabilities/depthpro/_views/estimate_request.py +63 -0
- kiapi/capabilities/embedding/README.ja.md +137 -0
- kiapi/capabilities/embedding/README.md +128 -0
- kiapi/capabilities/embedding/__init__.py +24 -0
- kiapi/capabilities/embedding/_constants/description.py +47 -0
- kiapi/capabilities/embedding/_helpers/register.py +66 -0
- kiapi/capabilities/embedding/_models/qwen3_text.py +53 -0
- kiapi/capabilities/embedding/_models/qwen3_vl.py +97 -0
- kiapi/capabilities/embedding/_operations/format_response.py +24 -0
- kiapi/capabilities/embedding/_operations/handle_embed.py +24 -0
- kiapi/capabilities/embedding/_operations/parse_inputs.py +108 -0
- kiapi/capabilities/embedding/_operations/resolve_embed_params.py +18 -0
- kiapi/capabilities/embedding/_settings.py +27 -0
- kiapi/capabilities/embedding/_utils/to_vector.py +20 -0
- kiapi/capabilities/embedding/_views/embed_params.py +17 -0
- kiapi/capabilities/embedding/_views/embed_request.py +39 -0
- kiapi/capabilities/ernie/README.ja.md +242 -0
- kiapi/capabilities/ernie/README.md +223 -0
- kiapi/capabilities/ernie/__init__.py +34 -0
- kiapi/capabilities/ernie/_constants/description.py +71 -0
- kiapi/capabilities/ernie/_helpers/register.py +60 -0
- kiapi/capabilities/ernie/_helpers/validate_edit.py +19 -0
- kiapi/capabilities/ernie/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/ernie/_models/ernie.py +356 -0
- kiapi/capabilities/ernie/_operations/handle_edit.py +39 -0
- kiapi/capabilities/ernie/_operations/handle_generate.py +38 -0
- kiapi/capabilities/ernie/_operations/handle_train.py +77 -0
- kiapi/capabilities/ernie/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/ernie/_operations/resolve_edit_params.py +44 -0
- kiapi/capabilities/ernie/_operations/resolve_generate_params.py +40 -0
- kiapi/capabilities/ernie/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/ernie/_operations/resolve_train_params.py +43 -0
- kiapi/capabilities/ernie/_operations/validate_common.py +33 -0
- kiapi/capabilities/ernie/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/ernie/_settings.py +151 -0
- kiapi/capabilities/ernie/_views/edit_params.py +36 -0
- kiapi/capabilities/ernie/_views/edit_request.py +142 -0
- kiapi/capabilities/ernie/_views/generate_params.py +32 -0
- kiapi/capabilities/ernie/_views/generate_request.py +127 -0
- kiapi/capabilities/ernie/_views/train_params.py +28 -0
- kiapi/capabilities/ernie/_views/train_request.py +96 -0
- kiapi/capabilities/flux2/README.ja.md +260 -0
- kiapi/capabilities/flux2/README.md +241 -0
- kiapi/capabilities/flux2/__init__.py +36 -0
- kiapi/capabilities/flux2/_constants/description.py +81 -0
- kiapi/capabilities/flux2/_helpers/register.py +98 -0
- kiapi/capabilities/flux2/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/flux2/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/flux2/_models/flux2.py +396 -0
- kiapi/capabilities/flux2/_operations/handle_edit.py +44 -0
- kiapi/capabilities/flux2/_operations/handle_generate.py +46 -0
- kiapi/capabilities/flux2/_operations/handle_train.py +105 -0
- kiapi/capabilities/flux2/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/flux2/_operations/resolve_edit_params.py +43 -0
- kiapi/capabilities/flux2/_operations/resolve_generate_params.py +44 -0
- kiapi/capabilities/flux2/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/flux2/_operations/resolve_train_params.py +42 -0
- kiapi/capabilities/flux2/_operations/role_spec.py +13 -0
- kiapi/capabilities/flux2/_operations/split_repo.py +11 -0
- kiapi/capabilities/flux2/_operations/validate_common.py +35 -0
- kiapi/capabilities/flux2/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/flux2/_settings.py +181 -0
- kiapi/capabilities/flux2/_views/edit_params.py +36 -0
- kiapi/capabilities/flux2/_views/edit_request.py +145 -0
- kiapi/capabilities/flux2/_views/generate_params.py +36 -0
- kiapi/capabilities/flux2/_views/generate_request.py +150 -0
- kiapi/capabilities/flux2/_views/train_params.py +32 -0
- kiapi/capabilities/flux2/_views/train_request.py +102 -0
- kiapi/capabilities/ideogram4/README.ja.md +230 -0
- kiapi/capabilities/ideogram4/README.md +219 -0
- kiapi/capabilities/ideogram4/__init__.py +24 -0
- kiapi/capabilities/ideogram4/_constants/description.py +65 -0
- kiapi/capabilities/ideogram4/_helpers/register.py +44 -0
- kiapi/capabilities/ideogram4/_helpers/validate_generate.py +31 -0
- kiapi/capabilities/ideogram4/_models/ideogram4.py +120 -0
- kiapi/capabilities/ideogram4/_operations/handle_generate.py +30 -0
- kiapi/capabilities/ideogram4/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/ideogram4/_operations/resolve_generate_params.py +30 -0
- kiapi/capabilities/ideogram4/_settings.py +89 -0
- kiapi/capabilities/ideogram4/_views/generate_params.py +27 -0
- kiapi/capabilities/ideogram4/_views/generate_request.py +118 -0
- kiapi/capabilities/ltx2/README.ja.md +287 -0
- kiapi/capabilities/ltx2/README.md +274 -0
- kiapi/capabilities/ltx2/__init__.py +26 -0
- kiapi/capabilities/ltx2/_constants/description.py +81 -0
- kiapi/capabilities/ltx2/_helpers/register.py +58 -0
- kiapi/capabilities/ltx2/_helpers/validate_generate.py +42 -0
- kiapi/capabilities/ltx2/_models/ltx2.py +106 -0
- kiapi/capabilities/ltx2/_operations/detect_mode.py +19 -0
- kiapi/capabilities/ltx2/_operations/handle_generate.py +52 -0
- kiapi/capabilities/ltx2/_operations/resolve_generate_params.py +31 -0
- kiapi/capabilities/ltx2/_settings.py +93 -0
- kiapi/capabilities/ltx2/_views/generate_params.py +34 -0
- kiapi/capabilities/ltx2/_views/generate_request.py +151 -0
- kiapi/capabilities/qwen/README.ja.md +251 -0
- kiapi/capabilities/qwen/README.md +235 -0
- kiapi/capabilities/qwen/__init__.py +30 -0
- kiapi/capabilities/qwen/_constants/description.py +53 -0
- kiapi/capabilities/qwen/_helpers/register.py +60 -0
- kiapi/capabilities/qwen/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/qwen/_helpers/validate_generate.py +12 -0
- kiapi/capabilities/qwen/_models/qwen.py +224 -0
- kiapi/capabilities/qwen/_operations/handle_edit.py +44 -0
- kiapi/capabilities/qwen/_operations/handle_generate.py +46 -0
- kiapi/capabilities/qwen/_operations/is_quantize_override.py +15 -0
- kiapi/capabilities/qwen/_operations/resolve_edit_params.py +35 -0
- kiapi/capabilities/qwen/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/qwen/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/qwen/_operations/validate_common.py +32 -0
- kiapi/capabilities/qwen/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/qwen/_settings.py +107 -0
- kiapi/capabilities/qwen/_views/edit_params.py +36 -0
- kiapi/capabilities/qwen/_views/edit_request.py +138 -0
- kiapi/capabilities/qwen/_views/generate_params.py +37 -0
- kiapi/capabilities/qwen/_views/generate_request.py +149 -0
- kiapi/capabilities/seedvr2/README.ja.md +234 -0
- kiapi/capabilities/seedvr2/README.md +219 -0
- kiapi/capabilities/seedvr2/__init__.py +24 -0
- kiapi/capabilities/seedvr2/_constants/description.py +46 -0
- kiapi/capabilities/seedvr2/_helpers/register.py +60 -0
- kiapi/capabilities/seedvr2/_helpers/validate_upscale.py +52 -0
- kiapi/capabilities/seedvr2/_models/seedvr2.py +140 -0
- kiapi/capabilities/seedvr2/_operations/handle_upscale.py +42 -0
- kiapi/capabilities/seedvr2/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/seedvr2/_operations/resolve_upscale_params.py +30 -0
- kiapi/capabilities/seedvr2/_settings.py +74 -0
- kiapi/capabilities/seedvr2/_views/upscale_params.py +27 -0
- kiapi/capabilities/seedvr2/_views/upscale_request.py +94 -0
- kiapi/capabilities/web/README.ja.md +187 -0
- kiapi/capabilities/web/README.md +171 -0
- kiapi/capabilities/web/__init__.py +30 -0
- kiapi/capabilities/web/_constants/description.py +38 -0
- kiapi/capabilities/web/_exceptions/FetchError.py +24 -0
- kiapi/capabilities/web/_exceptions/SearchBackendError.py +11 -0
- kiapi/capabilities/web/_helpers/register.py +59 -0
- kiapi/capabilities/web/_models/crawl4ai.py +32 -0
- kiapi/capabilities/web/_models/searxng.py +44 -0
- kiapi/capabilities/web/_operations/handle_fetch.py +145 -0
- kiapi/capabilities/web/_operations/handle_search.py +56 -0
- kiapi/capabilities/web/_operations/resolve_fetch_params.py +19 -0
- kiapi/capabilities/web/_operations/resolve_search_params.py +34 -0
- kiapi/capabilities/web/_operations/resolve_searxng_config_dir.py +21 -0
- kiapi/capabilities/web/_services/__init__.py +1 -0
- kiapi/capabilities/web/_services/web_backend_process.py +144 -0
- kiapi/capabilities/web/_settings.py +138 -0
- kiapi/capabilities/web/_views/fetch_params.py +27 -0
- kiapi/capabilities/web/_views/fetch_request.py +29 -0
- kiapi/capabilities/web/_views/fetch_result.py +20 -0
- kiapi/capabilities/web/_views/search_params.py +43 -0
- kiapi/capabilities/web/_views/search_request.py +93 -0
- kiapi/capabilities/web/_views/search_response.py +49 -0
- kiapi/capabilities/web/resources/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/settings.yml +11 -0
- kiapi/capabilities/zimage/README.ja.md +249 -0
- kiapi/capabilities/zimage/README.md +231 -0
- kiapi/capabilities/zimage/__init__.py +34 -0
- kiapi/capabilities/zimage/_constants/description.py +73 -0
- kiapi/capabilities/zimage/_helpers/register.py +62 -0
- kiapi/capabilities/zimage/_helpers/validate_generate.py +37 -0
- kiapi/capabilities/zimage/_models/zimage.py +278 -0
- kiapi/capabilities/zimage/_operations/handle_generate.py +38 -0
- kiapi/capabilities/zimage/_operations/handle_train.py +78 -0
- kiapi/capabilities/zimage/_operations/is_quantize_override.py +11 -0
- kiapi/capabilities/zimage/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/zimage/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/zimage/_operations/resolve_train_params.py +38 -0
- kiapi/capabilities/zimage/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/zimage/_settings.py +166 -0
- kiapi/capabilities/zimage/_views/generate_params.py +23 -0
- kiapi/capabilities/zimage/_views/generate_request.py +127 -0
- kiapi/capabilities/zimage/_views/train_params.py +22 -0
- kiapi/capabilities/zimage/_views/train_request.py +101 -0
- kiapi/cli/__init__.py +11 -0
- kiapi/cli/_helpers/dedupe_resources.py +12 -0
- kiapi/cli/_helpers/register_all_capabilities.py +36 -0
- kiapi/cli/_helpers/run_resources.py +24 -0
- kiapi/cli/_helpers/select_specs.py +67 -0
- kiapi/cli/activate/_operations/preflight_hf_access.py +129 -0
- kiapi/cli/activate/cli.py +37 -0
- kiapi/cli/check/_helpers/check_audio_acestep_turbo.py +22 -0
- kiapi/cli/check/_helpers/check_audio_acestep_xl_base.py +22 -0
- kiapi/cli/check/_helpers/check_audio_audiogen_medium.py +24 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_6_27b.py +19 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_omni.py +19 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_embedding_8b.py +14 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_vl_embedding_2b.py +19 -0
- kiapi/cli/check/_helpers/check_image_depthpro_base.py +21 -0
- kiapi/cli/check/_helpers/check_image_ernie_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_ernie_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_4b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_ideogram4_fp8.py +23 -0
- kiapi/cli/check/_helpers/check_image_qwen_edit_2509.py +27 -0
- kiapi/cli/check/_helpers/check_image_qwen_image.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_3b.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_7b.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_video_ltx2_distilled.py +26 -0
- kiapi/cli/check/_helpers/check_web_web_fetch.py +14 -0
- kiapi/cli/check/_helpers/check_web_web_search.py +14 -0
- kiapi/cli/check/_operations/build_check_result.py +20 -0
- kiapi/cli/check/_operations/check_context.py +10 -0
- kiapi/cli/check/_operations/create_sample_image.py +46 -0
- kiapi/cli/check/_schemas/check_result.py +12 -0
- kiapi/cli/check/cli.py +89 -0
- kiapi/cli/cli.py +29 -0
- kiapi/cli/config/cli.py +17 -0
- kiapi/cli/config/edit/cli.py +32 -0
- kiapi/cli/config/init/cli.py +33 -0
- kiapi/cli/config/show/cli.py +13 -0
- kiapi/cli/config/template/cli.py +36 -0
- kiapi/cli/deactivate/cli.py +49 -0
- kiapi/cli/run/asgi.py +16 -0
- kiapi/cli/run/cli.py +59 -0
- kiapi/cli/service/__init__.py +5 -0
- kiapi/cli/service/_services/service_manager.py +107 -0
- kiapi/cli/service/cli.py +19 -0
- kiapi/cli/service/install/cli.py +17 -0
- kiapi/cli/service/start/cli.py +22 -0
- kiapi/cli/service/status/cli.py +81 -0
- kiapi/cli/service/stop/cli.py +19 -0
- kiapi/cli/service/uninstall/cli.py +16 -0
- kiapi/cli/status/cli.py +226 -0
- kiapi/core/app/__init__.py +16 -0
- kiapi/core/app/_schemas/app_context.py +28 -0
- kiapi/core/app/_services/user_directory.py +59 -0
- kiapi/core/app/_settings.py +46 -0
- kiapi/core/capability/__init__.py +11 -0
- kiapi/core/capability/_schemas/capability_spec.py +17 -0
- kiapi/core/capability/_services/capability_spec_registry.py +21 -0
- kiapi/core/config/__init__.py +11 -0
- kiapi/core/config/_exceptions/user_config_error.py +2 -0
- kiapi/core/config/_helpers/get_user_settings_path.py +7 -0
- kiapi/core/config/_helpers/load_user_settings.py +54 -0
- kiapi/core/file/__init__.py +37 -0
- kiapi/core/file/_helpers/create_file_store.py +7 -0
- kiapi/core/file/_helpers/resolve_file_ref.py +90 -0
- kiapi/core/file/_schemas/file_data_url_ref.py +19 -0
- kiapi/core/file/_schemas/file_id_ref.py +16 -0
- kiapi/core/file/_schemas/file_record.py +46 -0
- kiapi/core/file/_schemas/file_url_ref.py +16 -0
- kiapi/core/file/_services/file_store.py +138 -0
- kiapi/core/file/_settings.py +22 -0
- kiapi/core/file/_types/file_id.py +2 -0
- kiapi/core/file/_types/file_ref.py +12 -0
- kiapi/core/file/_views/resolved_file_ref.py +16 -0
- kiapi/core/job/__init__.py +24 -0
- kiapi/core/job/_enums/job_status.py +9 -0
- kiapi/core/job/_helpers/creep_progress.py +123 -0
- kiapi/core/job/_models/job.py +121 -0
- kiapi/core/job/_services/job_store.py +33 -0
- kiapi/core/job/_services/progress_reporter.py +79 -0
- kiapi/core/job/_types/job_id.py +3 -0
- kiapi/core/job/_types/job_result.py +5 -0
- kiapi/core/job/_types/job_type.py +4 -0
- kiapi/core/logging/__init__.py +14 -0
- kiapi/core/logging/_helpers/get_log_level.py +8 -0
- kiapi/core/logging/_helpers/setup_logger.py +14 -0
- kiapi/core/logging/_settings.py +34 -0
- kiapi/core/logging/_types/log_level.py +3 -0
- kiapi/core/memory/__init__.py +21 -0
- kiapi/core/memory/_exceptions/memory_budget_error.py +2 -0
- kiapi/core/memory/_helpers/create_memory_manager.py +17 -0
- kiapi/core/memory/_operations/log_memory_limit.py +29 -0
- kiapi/core/memory/_operations/resolve_effective_memory_limit_gb.py +13 -0
- kiapi/core/memory/_operations/resolve_framework_strategy.py +42 -0
- kiapi/core/memory/_schemas/framework_strategy.py +14 -0
- kiapi/core/memory/_schemas/memory_stats.py +24 -0
- kiapi/core/memory/_schemas/resident_model.py +14 -0
- kiapi/core/memory/_schemas/resident_model_stats.py +49 -0
- kiapi/core/memory/_services/memory_manager.py +257 -0
- kiapi/core/memory/_settings.py +36 -0
- kiapi/core/memory/_types/framework_name.py +4 -0
- kiapi/core/memory/_types/resident_key.py +4 -0
- kiapi/core/model/__init__.py +36 -0
- kiapi/core/model/_exceptions/unknown_model_error.py +2 -0
- kiapi/core/model/_schemas/model_spec.py +145 -0
- kiapi/core/model/_services/model_registry.py +85 -0
- kiapi/core/model/_types/model_alias.py +2 -0
- kiapi/core/model/_types/model_domain.py +6 -0
- kiapi/core/model/_types/model_family.py +5 -0
- kiapi/core/model/_types/model_key.py +8 -0
- kiapi/core/model/_types/model_name.py +4 -0
- kiapi/core/model/_types/model_repo.py +3 -0
- kiapi/core/net/__init__.py +16 -0
- kiapi/core/net/_exceptions/unsafe_url_error.py +7 -0
- kiapi/core/net/_helpers/verify_public_url.py +68 -0
- kiapi/core/net/_settings.py +28 -0
- kiapi/core/setup/__init__.py +25 -0
- kiapi/core/setup/_exceptions/setup_required_error.py +2 -0
- kiapi/core/setup/_schemas/docker_image_resource.py +37 -0
- kiapi/core/setup/_schemas/hf_snapshot_resource.py +50 -0
- kiapi/core/setup/_schemas/local_path_resource.py +43 -0
- kiapi/core/setup/_schemas/python_package_resource.py +58 -0
- kiapi/core/setup/_schemas/python_venv_resource.py +63 -0
- kiapi/core/setup/_schemas/setup_status.py +7 -0
- kiapi/core/setup/_schemas/url_file_resource.py +43 -0
- kiapi/core/setup/_services/setup_manager.py +331 -0
- kiapi/core/setup/_types/setup_resource.py +21 -0
- kiapi/core/setup/_types/setup_target.py +11 -0
- kiapi/core/workdir/__init__.py +8 -0
- kiapi/core/workdir/_helpers/create_work_dir.py +11 -0
- kiapi/core/workdir/_settings.py +21 -0
- kiapi/core/worker/__init__.py +23 -0
- kiapi/core/worker/_helpers/create_worker.py +9 -0
- kiapi/core/worker/_services/worker.py +165 -0
- kiapi/core/worker/_settings.py +36 -0
- kiapi/core/worker/_types/job_thunk.py +6 -0
- kiapi-0.1.0.dist-info/METADATA +337 -0
- kiapi-0.1.0.dist-info/RECORD +465 -0
- kiapi-0.1.0.dist-info/WHEEL +4 -0
- kiapi-0.1.0.dist-info/entry_points.txt +2 -0
- kiapi-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""ace-step worker subprocess — runs under the ace-step venv (transformers 4.x).
|
|
2
|
+
|
|
3
|
+
kiapi's main process can't import ``acestep`` (it pins transformers 4.x, which
|
|
4
|
+
conflicts with chat/embedding's transformers 5.x). So ace-step
|
|
5
|
+
generation runs here, in a separate Python launched from the ace-step venv, and
|
|
6
|
+
kiapi talks to it over a tiny line-oriented JSON protocol on stdin/stdout.
|
|
7
|
+
|
|
8
|
+
This module is NEVER imported by kiapi; it is executed as a script:
|
|
9
|
+
|
|
10
|
+
<ace-step-venv>/bin/python -m ... worker_subprocess.py \
|
|
11
|
+
--preset-name xl-base --project-root <dir> \
|
|
12
|
+
--checkpoint-dir <dir>/checkpoints --llm-model acestep-5Hz-lm-1.7B
|
|
13
|
+
|
|
14
|
+
Protocol (one JSON object per line):
|
|
15
|
+
- stdout, on ready: @@KIAPI@@{"event":"ready"}
|
|
16
|
+
- stdin, one request/line: {"id":"..","task":"text2music","params":{...},"save_dir":".."}
|
|
17
|
+
- stdout, progress/line: @@KIAPI@@{"id":"..","event":"progress","fraction":0.5,"label":".."}
|
|
18
|
+
- stdout, one reply/line: @@KIAPI@@{"id":"..","ok":true,"path":".."}
|
|
19
|
+
or @@KIAPI@@{"id":"..","ok":false,"error":".."}
|
|
20
|
+
|
|
21
|
+
ace-step's ``generate_music`` takes a Gradio-style ``progress(fraction, desc=...)``
|
|
22
|
+
callback that fires at real milestones (LLM phases, a self-calibrating diffusion
|
|
23
|
+
estimator, decode, finalize). We pass one that re-emits each call as a
|
|
24
|
+
``progress`` protocol line tagged with the request id; the kiapi side forwards it
|
|
25
|
+
onto the job's :class:`ProgressReporter`. Any number of progress lines may precede
|
|
26
|
+
the single terminal reply for a request.
|
|
27
|
+
|
|
28
|
+
All library logging is redirected to stderr so fd 1 carries only ``@@KIAPI@@``-
|
|
29
|
+
prefixed protocol lines (kiapi ignores any other stdout noise defensively).
|
|
30
|
+
The generation logic (_build_params + presets) is ported verbatim from
|
|
31
|
+
ace-step-1.5-server's main.py so behavior is identical.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import argparse
|
|
35
|
+
import json
|
|
36
|
+
import os
|
|
37
|
+
import sys
|
|
38
|
+
import traceback
|
|
39
|
+
from dataclasses import dataclass
|
|
40
|
+
from pathlib import Path
|
|
41
|
+
|
|
42
|
+
# Keep fd 1 clean for the protocol: send every library print()/log to stderr.
|
|
43
|
+
_PROTO_OUT = sys.__stdout__
|
|
44
|
+
sys.stdout = sys.stderr
|
|
45
|
+
|
|
46
|
+
SENTINEL = "@@KIAPI@@"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _emit(obj: dict) -> None:
|
|
50
|
+
_PROTO_OUT.write(SENTINEL + json.dumps(obj, ensure_ascii=False) + "\n") # type: ignore
|
|
51
|
+
_PROTO_OUT.flush() # type: ignore
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _make_progress(rid): # type: ignore
|
|
55
|
+
def _progress(value=0.0, desc=None, *args, **kwargs): # type: ignore
|
|
56
|
+
try:
|
|
57
|
+
_emit(
|
|
58
|
+
{
|
|
59
|
+
"id": rid,
|
|
60
|
+
"event": "progress",
|
|
61
|
+
"fraction": float(value),
|
|
62
|
+
"label": desc if isinstance(desc, str) else None,
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
except Exception:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
return _progress
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# --- model presets (ported from ace-step-1.5-server/main.py) -----------------
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass
|
|
75
|
+
class ModelPreset:
|
|
76
|
+
config_path: str
|
|
77
|
+
inference_steps: int
|
|
78
|
+
guidance_scale: float
|
|
79
|
+
shift: float
|
|
80
|
+
use_adg: bool
|
|
81
|
+
dcw_enabled: bool
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
PRESETS: dict[str, ModelPreset] = {
|
|
85
|
+
"turbo": ModelPreset(
|
|
86
|
+
config_path="acestep-v15-turbo",
|
|
87
|
+
inference_steps=8,
|
|
88
|
+
guidance_scale=1.0,
|
|
89
|
+
shift=3.0,
|
|
90
|
+
use_adg=False,
|
|
91
|
+
dcw_enabled=True,
|
|
92
|
+
),
|
|
93
|
+
"xl-base": ModelPreset(
|
|
94
|
+
config_path="acestep-v15-xl-base",
|
|
95
|
+
inference_steps=32,
|
|
96
|
+
guidance_scale=7.0,
|
|
97
|
+
shift=3.0,
|
|
98
|
+
use_adg=False,
|
|
99
|
+
dcw_enabled=False,
|
|
100
|
+
),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _build_params(task: str, p: dict, preset: ModelPreset): # type: ignore
|
|
105
|
+
"""Map a protocol request into ace-step GenerationParams. Ported verbatim."""
|
|
106
|
+
from acestep.inference import GenerationParams # type: ignore
|
|
107
|
+
|
|
108
|
+
common = {
|
|
109
|
+
"inference_steps": p.get("inference_steps") or preset.inference_steps,
|
|
110
|
+
"guidance_scale": p["guidance_scale"]
|
|
111
|
+
if p.get("guidance_scale") is not None
|
|
112
|
+
else preset.guidance_scale,
|
|
113
|
+
"shift": p["shift"] if p.get("shift") is not None else preset.shift,
|
|
114
|
+
"use_adg": preset.use_adg,
|
|
115
|
+
"dcw_enabled": preset.dcw_enabled,
|
|
116
|
+
"seed": p.get("seed", -1),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if task == "text2music":
|
|
120
|
+
return GenerationParams(
|
|
121
|
+
task_type="text2music",
|
|
122
|
+
thinking=True,
|
|
123
|
+
caption=p["prompt"],
|
|
124
|
+
lyrics=p.get("lyrics", "[Instrumental]"),
|
|
125
|
+
vocal_language=p.get("lang", "ja"),
|
|
126
|
+
duration=p.get("duration", 60),
|
|
127
|
+
**common,
|
|
128
|
+
)
|
|
129
|
+
if task == "cover":
|
|
130
|
+
return GenerationParams(
|
|
131
|
+
task_type="cover",
|
|
132
|
+
thinking=False,
|
|
133
|
+
caption=p["prompt"],
|
|
134
|
+
lyrics="[Instrumental]",
|
|
135
|
+
src_audio=p["src_audio"],
|
|
136
|
+
audio_cover_strength=p.get("strength", 0.7),
|
|
137
|
+
duration=p.get("duration"),
|
|
138
|
+
**common,
|
|
139
|
+
)
|
|
140
|
+
if task == "repaint":
|
|
141
|
+
return GenerationParams(
|
|
142
|
+
task_type="repaint",
|
|
143
|
+
thinking=False,
|
|
144
|
+
caption=p["prompt"],
|
|
145
|
+
lyrics="[Instrumental]",
|
|
146
|
+
src_audio=p["src_audio"],
|
|
147
|
+
repainting_start=p["start"],
|
|
148
|
+
repainting_end=p.get("end", -1),
|
|
149
|
+
repaint_strength=p.get("strength", 0.5),
|
|
150
|
+
**common,
|
|
151
|
+
)
|
|
152
|
+
if task == "extract":
|
|
153
|
+
return GenerationParams(
|
|
154
|
+
task_type="extract",
|
|
155
|
+
thinking=False,
|
|
156
|
+
caption=p["target"],
|
|
157
|
+
lyrics="[Instrumental]",
|
|
158
|
+
src_audio=p["src_audio"],
|
|
159
|
+
**common,
|
|
160
|
+
)
|
|
161
|
+
raise ValueError(f"unknown task: {task!r}")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# --- handlers ----------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def main() -> None:
|
|
168
|
+
ap = argparse.ArgumentParser()
|
|
169
|
+
ap.add_argument("--preset-name", required=True, choices=list(PRESETS))
|
|
170
|
+
ap.add_argument("--project-root", required=True)
|
|
171
|
+
ap.add_argument("--checkpoint-dir", required=True)
|
|
172
|
+
ap.add_argument("--llm-model", required=True)
|
|
173
|
+
args = ap.parse_args()
|
|
174
|
+
|
|
175
|
+
preset = PRESETS[args.preset_name]
|
|
176
|
+
|
|
177
|
+
# Pin where ace-step finds the checkpoints (highest-priority lever in its
|
|
178
|
+
# get_checkpoints_dir resolution), so kiapi's checkpoint_dir is authoritative
|
|
179
|
+
# regardless of project_root layout. Must be set before importing acestep.
|
|
180
|
+
os.environ.setdefault("ACESTEP_CHECKPOINTS_DIR", args.checkpoint_dir)
|
|
181
|
+
|
|
182
|
+
from acestep.handler import AceStepHandler # type: ignore
|
|
183
|
+
from acestep.inference import GenerationConfig, generate_music
|
|
184
|
+
from acestep.llm_inference import LLMHandler # type: ignore
|
|
185
|
+
|
|
186
|
+
# Load the shared LLM + this preset's DiT (mirrors the original server).
|
|
187
|
+
llm = LLMHandler()
|
|
188
|
+
msg, ok = llm.initialize(
|
|
189
|
+
checkpoint_dir=args.checkpoint_dir,
|
|
190
|
+
lm_model_path=args.llm_model,
|
|
191
|
+
backend="mlx",
|
|
192
|
+
device="auto",
|
|
193
|
+
offload_to_cpu=False,
|
|
194
|
+
dtype=None,
|
|
195
|
+
)
|
|
196
|
+
if not ok:
|
|
197
|
+
_emit({"event": "error", "error": f"LLM init failed: {msg}"})
|
|
198
|
+
sys.exit(1)
|
|
199
|
+
|
|
200
|
+
dit = AceStepHandler()
|
|
201
|
+
msg, ok = dit.initialize_service(
|
|
202
|
+
project_root=args.project_root,
|
|
203
|
+
config_path=preset.config_path,
|
|
204
|
+
device="auto",
|
|
205
|
+
offload_to_cpu=False,
|
|
206
|
+
)
|
|
207
|
+
if not ok:
|
|
208
|
+
_emit({"event": "error", "error": f"DiT init failed: {msg}"})
|
|
209
|
+
sys.exit(1)
|
|
210
|
+
|
|
211
|
+
_emit({"event": "ready", "preset": args.preset_name})
|
|
212
|
+
|
|
213
|
+
for line in sys.stdin:
|
|
214
|
+
line = line.strip()
|
|
215
|
+
if not line:
|
|
216
|
+
continue
|
|
217
|
+
try:
|
|
218
|
+
req = json.loads(line)
|
|
219
|
+
except json.JSONDecodeError:
|
|
220
|
+
continue
|
|
221
|
+
rid = req.get("id")
|
|
222
|
+
try:
|
|
223
|
+
params = _build_params(req["task"], req["params"], preset)
|
|
224
|
+
config = GenerationConfig(batch_size=1, audio_format="wav")
|
|
225
|
+
result = generate_music(
|
|
226
|
+
dit,
|
|
227
|
+
llm,
|
|
228
|
+
params=params,
|
|
229
|
+
config=config,
|
|
230
|
+
save_dir=req["save_dir"],
|
|
231
|
+
progress=_make_progress(rid),
|
|
232
|
+
)
|
|
233
|
+
if not getattr(result, "success", False):
|
|
234
|
+
raise RuntimeError(
|
|
235
|
+
getattr(result, "status_message", "generation failed")
|
|
236
|
+
)
|
|
237
|
+
path = result.audios[0].get("path", "")
|
|
238
|
+
if not path or not Path(path).exists():
|
|
239
|
+
raise RuntimeError("generation finished but no audio file was produced")
|
|
240
|
+
_emit({"id": rid, "ok": True, "path": path})
|
|
241
|
+
except Exception as exc:
|
|
242
|
+
traceback.print_exc()
|
|
243
|
+
_emit({"id": rid, "ok": False, "error": f"{type(exc).__name__}: {exc}"})
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
if __name__ == "__main__":
|
|
247
|
+
main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# audiogen
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **日本語**
|
|
4
|
+
|
|
5
|
+
[AudioGen](https://huggingface.co/facebook/audiogen-medium) で、効果音生成機能を提供します。
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
| Endpoint | Name | Description |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `POST /v1/audio/audiogen/generate` | 効果音生成 | プロンプトから効果音を生成。**16 kHz モノラル WAV 最大10秒**。 |
|
|
12
|
+
| `GET /v1/audio/audiogen/models` | モデル一覧 | 利用可能なモデルの一覧を返す。 |
|
|
13
|
+
| `GET /v1/audio/audiogen/openapi.json` | OpenAPI | 詳細な入出力仕様、使い方、TIPS を返す。 |
|
|
14
|
+
|
|
15
|
+
## API Docs
|
|
16
|
+
|
|
17
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/audio/audiogen/openapi.json)
|
|
18
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/audio/audiogen/docs.html)
|
|
19
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/audio/audiogen/redoc.html)
|
|
20
|
+
|
|
21
|
+
## Dependencies
|
|
22
|
+
|
|
23
|
+
| Package | License | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| [mlx-audiocraft](https://github.com/theashishmaurya/mlx-audiocraft) | MIT | Meta AudioCraft の AudioGen を MLX へ移植。 |
|
|
26
|
+
|
|
27
|
+
## Models
|
|
28
|
+
|
|
29
|
+
| Model | License | Terms | Size | Description |
|
|
30
|
+
|---|---|---|---:|---|
|
|
31
|
+
| [facebook/audiogen-medium](https://huggingface.co/facebook/audiogen-medium) | CC-BY-NC-4.0 | 不要 | 3.6 GB | **非商用ライセンス**。16 kHz モノラル、約 0.5 倍速(5 秒のクリップで約 10 秒の計算)。 |
|
|
32
|
+
|
|
33
|
+
## Quickstart
|
|
34
|
+
|
|
35
|
+
### generate — 効果音生成
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
jq -n \
|
|
39
|
+
--arg prompt "heavy rain on a tin roof, distant thunder" \
|
|
40
|
+
'{
|
|
41
|
+
mode: "sync",
|
|
42
|
+
prompt: $prompt,
|
|
43
|
+
duration: 5
|
|
44
|
+
}' |
|
|
45
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/audio/audiogen/generate \
|
|
46
|
+
-H 'Content-Type: application/json' \
|
|
47
|
+
--data-binary @- \
|
|
48
|
+
-o sfx.wav
|
|
49
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# audiogen
|
|
2
|
+
|
|
3
|
+
**English** | [日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
[AudioGen](https://huggingface.co/facebook/audiogen-medium) provides sound effect generation functionality.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
| Endpoint | Name | Description |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `POST /v1/audio/audiogen/generate` | Sound effect generation | Generate sound effects from prompts. **16 kHz monaural WAV up to 10 seconds**. |
|
|
12
|
+
| `GET /v1/audio/audiogen/models` | Model list | Returns a list of available models. |
|
|
13
|
+
| `GET /v1/audio/audiogen/openapi.json` | OpenAPI | Returns detailed input/output specifications, usage, and TIPS. |
|
|
14
|
+
|
|
15
|
+
## API Docs
|
|
16
|
+
|
|
17
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/audio/audiogen/openapi.json)
|
|
18
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/audio/audiogen/docs.html)
|
|
19
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/audio/audiogen/redoc.html)
|
|
20
|
+
|
|
21
|
+
## Dependencies
|
|
22
|
+
|
|
23
|
+
| Package | License | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| [mlx-audiocraft](https://github.com/theashishmaurya/mlx-audiocraft) | MIT | Porting Meta AudioCraft's AudioGen to MLX. |
|
|
26
|
+
|
|
27
|
+
## Models
|
|
28
|
+
|
|
29
|
+
| Model | License | Terms | Size | Description |
|
|
30
|
+
|---|---|---|---:|---|
|
|
31
|
+
| [facebook/audiogen-medium](https://huggingface.co/facebook/audiogen-medium) | CC-BY-NC-4.0 | Not required | 3.6 GB | **Non-Commercial License**. 16 kHz monaural, approximately 0.5x speed (approximately 10 seconds calculation for a 5 second clip). |
|
|
32
|
+
|
|
33
|
+
## Quickstart
|
|
34
|
+
|
|
35
|
+
### generate — sound effect generation
|
|
36
|
+
```bash
|
|
37
|
+
jq -n \
|
|
38
|
+
--arg prompt "heavy rain on a tin roof, distant thunder" \
|
|
39
|
+
'{
|
|
40
|
+
mode: "sync",
|
|
41
|
+
prompt: $prompt,
|
|
42
|
+
duration: 5
|
|
43
|
+
}' |
|
|
44
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/audio/audiogen/generate \
|
|
45
|
+
-H 'Content-Type: application/json' \
|
|
46
|
+
--data-binary @- \
|
|
47
|
+
-o sfx.wav
|
|
48
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""audiogen family — text→sound-effect via AudioGen (mlx-audiocraft).
|
|
2
|
+
|
|
3
|
+
Integrates mlx-audiocraft-server. Endpoint: ``POST /v1/audio/audiogen/generate``;
|
|
4
|
+
sync/async via `mode`, artifacts in the Files API. ``weight_gb`` measured on
|
|
5
|
+
device (model card ~3.6 GB). The variant ``medium`` is the only AudioGen size;
|
|
6
|
+
the family name (audiogen) is the AudioGen model family, distinct from the
|
|
7
|
+
mlx-audiocraft library (which also hosts MusicGen).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from kiapi.capabilities import ValidationError
|
|
11
|
+
|
|
12
|
+
from ._helpers.register import register
|
|
13
|
+
from ._helpers.validate_generate import validate_generate
|
|
14
|
+
from ._operations.handle_generate import handle_generate
|
|
15
|
+
from ._settings import settings_manager
|
|
16
|
+
from ._views.generate_request import GenerateRequest
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"GenerateRequest",
|
|
20
|
+
"ValidationError",
|
|
21
|
+
"handle_generate",
|
|
22
|
+
"register",
|
|
23
|
+
"settings_manager",
|
|
24
|
+
"validate_generate",
|
|
25
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
DESCRIPTION = """Sound-effect / ambient audio generation from text.
|
|
2
|
+
|
|
3
|
+
AudioGen turns a text prompt into short non-musical audio events: environmental
|
|
4
|
+
sounds, foley, impacts, ambience, machinery, footsteps, room tone, and similar
|
|
5
|
+
SFX. Output is always 16 kHz mono WAV. It is not a music model — for songs,
|
|
6
|
+
vocals, cover, repaint, or stem extraction use the ACE-Step family instead.
|
|
7
|
+
|
|
8
|
+
## Upstream docs
|
|
9
|
+
- [AudioGen medium](https://huggingface.co/facebook/audiogen-medium) — the
|
|
10
|
+
upstream model card
|
|
11
|
+
- [mlx-audiocraft](https://github.com/theashishmaurya/mlx-audiocraft) — MLX port
|
|
12
|
+
of Meta AudioCraft
|
|
13
|
+
|
|
14
|
+
## Models
|
|
15
|
+
- **medium** (default) — `facebook/audiogen-medium`, 1.5B parameters, native up
|
|
16
|
+
to 10 seconds. The model is CC-BY-NC-4.0, so check the license before use.
|
|
17
|
+
|
|
18
|
+
Discover variants at `GET /v1/audio/audiogen/models`.
|
|
19
|
+
|
|
20
|
+
## Prompt Tips
|
|
21
|
+
Be concrete and additive. Name the source, action, material, distance, space, and
|
|
22
|
+
energy:
|
|
23
|
+
- **good**: "heavy rain on a tin roof, distant thunder, wide outdoor ambience"
|
|
24
|
+
- **good**: "slow footsteps on wet gravel, close microphone, quiet night street"
|
|
25
|
+
- **less useful**: "rain" or "scary sound"
|
|
26
|
+
|
|
27
|
+
Sampling tweaks matter less than wording. Start with `duration`, `seed`, and
|
|
28
|
+
`cfg_coef`; only adjust `top_k`, `top_p`, and `temperature` when exploring
|
|
29
|
+
variation.
|
|
30
|
+
|
|
31
|
+
## Reproducibility
|
|
32
|
+
Set `seed` to reproduce a clip with the same prompt and sampling parameters.
|
|
33
|
+
Leave it null to explore alternatives; the resolved seed is recorded in the Job
|
|
34
|
+
`result.params`.
|
|
35
|
+
|
|
36
|
+
## Performance
|
|
37
|
+
- First request after activate/idle may spend tens of seconds loading weights.
|
|
38
|
+
- After loading, the model stays resident until idle TTL or memory budget pressure
|
|
39
|
+
frees it.
|
|
40
|
+
- On M4 Max, generation is roughly half realtime: a 5 second clip takes about
|
|
41
|
+
10 seconds of compute.
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### Generate raw WAV (sync)
|
|
46
|
+
```sh
|
|
47
|
+
curl -sS http://localhost:${PORT:-8000}/v1/audio/audiogen/generate \\
|
|
48
|
+
-H 'Content-Type: application/json' \\
|
|
49
|
+
-d '{"mode":"sync","prompt":"keyboard typing, office ambience","duration":5}' \\
|
|
50
|
+
-o sfx.wav
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Generate as async job
|
|
54
|
+
```sh
|
|
55
|
+
curl -sS http://localhost:${PORT:-8000}/v1/audio/audiogen/generate \\
|
|
56
|
+
-H 'Content-Type: application/json' \\
|
|
57
|
+
-d '{"mode":"async","prompt":"ocean waves crashing on rocks","duration":5,"seed":42}'
|
|
58
|
+
# -> {"job_id": "..."}; poll GET /v1/jobs/{job_id}
|
|
59
|
+
```
|
|
60
|
+
"""
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Register a token-generation progress callback on an AudioGen model.
|
|
2
|
+
|
|
3
|
+
Called right before ``model.generate(..., progress=True)`` in the audiogen
|
|
4
|
+
generation helper. ``mlx_audiocraft``'s ``AudioGen`` exposes a single progress
|
|
5
|
+
slot via ``set_custom_progress_callback`` and invokes it once per autoregressive
|
|
6
|
+
decode step with ``(generated_tokens, tokens_to_generate)`` (see
|
|
7
|
+
``genmodel._generate_tokens`` / ``lm.generate``).
|
|
8
|
+
|
|
9
|
+
The callback holds no per-job state — it reads the job's ambient
|
|
10
|
+
:class:`ProgressReporter` (see core/job) each step — so a single instance can stay
|
|
11
|
+
registered on the resident model and serve every job (silently no-op when no job
|
|
12
|
+
is bound). Unlike mflux's callback registry this is a single slot, so re-setting
|
|
13
|
+
it on each call is naturally idempotent.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from kiapi.core.job import ProgressReporter
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def attach_audiogen_progress(model: Any, *, label: str = "generating") -> None:
|
|
22
|
+
def _callback(generated_tokens: int, tokens_to_generate: int) -> None:
|
|
23
|
+
ProgressReporter.current().step(
|
|
24
|
+
int(generated_tokens), int(tokens_to_generate), label
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
model.set_custom_progress_callback(_callback)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Register audiogen's models + OpenAPI description in the global registries."""
|
|
2
|
+
|
|
3
|
+
from kiapi.core.capability import CapabilitySpec, capability_spec_registry
|
|
4
|
+
from kiapi.core.model import ModelSpec, model_registry
|
|
5
|
+
from kiapi.core.setup import HfSnapshotResource
|
|
6
|
+
|
|
7
|
+
from .._constants.description import DESCRIPTION
|
|
8
|
+
from .._models import audiogen
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def register() -> None:
|
|
12
|
+
capability_spec_registry.register(
|
|
13
|
+
CapabilitySpec(
|
|
14
|
+
name="audiogen",
|
|
15
|
+
domain="audio",
|
|
16
|
+
title="kiapi AudioGen API",
|
|
17
|
+
summary="Generate short sound effects from text prompts.",
|
|
18
|
+
description=DESCRIPTION,
|
|
19
|
+
openapi_path="/v1/audio/audiogen/openapi.json",
|
|
20
|
+
docs_path="/v1/audio/audiogen/docs",
|
|
21
|
+
redoc_path="/v1/audio/audiogen/redoc",
|
|
22
|
+
path_prefixes=("/v1/audio/audiogen",),
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
model_registry.register(
|
|
27
|
+
ModelSpec(
|
|
28
|
+
name="medium",
|
|
29
|
+
family="audiogen",
|
|
30
|
+
domain="audio",
|
|
31
|
+
repo="facebook/audiogen-medium",
|
|
32
|
+
module=audiogen,
|
|
33
|
+
weight_gb=7.1, # measured on device (model card weights ~3.6 GB)
|
|
34
|
+
peak_headroom_gb=2.0,
|
|
35
|
+
framework="mlx",
|
|
36
|
+
priority=0,
|
|
37
|
+
default=True,
|
|
38
|
+
setup_resources=(
|
|
39
|
+
HfSnapshotResource(repo="facebook/audiogen-medium", disk_gb=3.6),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from kiapi.capabilities import ValidationError
|
|
2
|
+
|
|
3
|
+
from .._settings import settings_manager
|
|
4
|
+
from .._views.generate_request import GenerateRequest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def validate_generate(req: GenerateRequest, *, variant: str) -> None:
|
|
8
|
+
del variant
|
|
9
|
+
|
|
10
|
+
settings = settings_manager.get_settings()
|
|
11
|
+
if req.duration > settings.max_duration:
|
|
12
|
+
raise ValidationError(
|
|
13
|
+
f"duration {req.duration}s exceeds max {settings.max_duration}s"
|
|
14
|
+
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Handler for AudioGen (text → sound effect; ``facebook/audiogen-medium``).
|
|
2
|
+
|
|
3
|
+
Owns the load + generate flow, ported from mlx-audiocraft-server's
|
|
4
|
+
generation.run_generation. Generates a 16 kHz mono WAV, stores it in the global
|
|
5
|
+
file store, and returns the artifact metadata (the job's ``result``).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import time
|
|
9
|
+
from types import SimpleNamespace
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from kiapi.core.file import FileStore
|
|
13
|
+
from kiapi.core.model import ModelSpec
|
|
14
|
+
from kiapi.core.workdir import create_work_dir
|
|
15
|
+
|
|
16
|
+
from .._helpers.attach_audiogen_progress import attach_audiogen_progress
|
|
17
|
+
from .._views.generate_params import GenerateParams
|
|
18
|
+
|
|
19
|
+
FEATURES = {"text"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def load(spec: ModelSpec) -> SimpleNamespace:
|
|
23
|
+
from mlx_audiocraft import AudioGen # type: ignore
|
|
24
|
+
|
|
25
|
+
model = AudioGen.get_pretrained(spec.repo)
|
|
26
|
+
return SimpleNamespace(model=model)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def warmup(payload: SimpleNamespace) -> None:
|
|
30
|
+
"""Prime weights + MLX kernels with a tiny generation (artifact discarded)."""
|
|
31
|
+
model = payload.model
|
|
32
|
+
model.set_generation_params(duration=1.0)
|
|
33
|
+
model.generate(["click"])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run(
|
|
37
|
+
payload: SimpleNamespace,
|
|
38
|
+
params: GenerateParams,
|
|
39
|
+
files: FileStore,
|
|
40
|
+
) -> dict[str, Any]:
|
|
41
|
+
"""Blocking generation on the resident model. Returns artifact metadata."""
|
|
42
|
+
import mlx.core as mx
|
|
43
|
+
import numpy as np
|
|
44
|
+
import soundfile as sf # type: ignore
|
|
45
|
+
|
|
46
|
+
model = payload.model
|
|
47
|
+
|
|
48
|
+
mx.random.seed(params.seed)
|
|
49
|
+
|
|
50
|
+
model.set_generation_params(
|
|
51
|
+
duration=params.duration,
|
|
52
|
+
top_k=params.top_k,
|
|
53
|
+
top_p=params.top_p,
|
|
54
|
+
temperature=params.temperature,
|
|
55
|
+
cfg_coef=params.cfg_coef,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
attach_audiogen_progress(model)
|
|
59
|
+
|
|
60
|
+
t0 = time.time()
|
|
61
|
+
wavs = model.generate([params.prompt], progress=True) # [B, C, T] mlx array
|
|
62
|
+
total_s = round(time.time() - t0, 2)
|
|
63
|
+
|
|
64
|
+
# [B, C, T] -> [T, C] (soundfile wants samples-major); squeeze mono to 1-D.
|
|
65
|
+
arr = np.array(wavs[0]) # [C, T]
|
|
66
|
+
arr = arr.T # [T, C]
|
|
67
|
+
if arr.shape[1] == 1:
|
|
68
|
+
arr = arr[:, 0]
|
|
69
|
+
|
|
70
|
+
sample_rate = int(model.sample_rate)
|
|
71
|
+
tmp_dir = create_work_dir("audio/audiogen")
|
|
72
|
+
tmp_wav = tmp_dir / "se.wav"
|
|
73
|
+
sf.write(str(tmp_wav), arr, sample_rate)
|
|
74
|
+
if not tmp_wav.exists():
|
|
75
|
+
raise RuntimeError("generation finished but no audio file was produced")
|
|
76
|
+
|
|
77
|
+
duration_s = round(arr.shape[0] / sample_rate, 3)
|
|
78
|
+
meta = {
|
|
79
|
+
"model": params.model,
|
|
80
|
+
"prompt": params.prompt,
|
|
81
|
+
"params": params.model_dump(),
|
|
82
|
+
"duration_s": duration_s,
|
|
83
|
+
"sample_rate": sample_rate,
|
|
84
|
+
"timings": {"total_s": total_s},
|
|
85
|
+
}
|
|
86
|
+
rec = files.put_path(
|
|
87
|
+
tmp_wav,
|
|
88
|
+
filename=f"se_{int(time.time())}.wav",
|
|
89
|
+
content_type="audio/wav",
|
|
90
|
+
meta=meta,
|
|
91
|
+
move=True,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
"file_id": rec.file_id,
|
|
96
|
+
"audio_bytes": rec.size,
|
|
97
|
+
**meta,
|
|
98
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Sound-effect service entry: resolve → acquire (memory budget) → generate.
|
|
2
|
+
|
|
3
|
+
Body of the se job's worker-thread thunk. The handler writes its WAV artifact to
|
|
4
|
+
the global file store and returns metadata; the job's ``artifacts`` is the
|
|
5
|
+
produced file_id.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from kiapi.core.app import AppContext
|
|
9
|
+
from kiapi.core.file import FileID
|
|
10
|
+
from kiapi.core.job import JobResult
|
|
11
|
+
from kiapi.core.model import model_registry
|
|
12
|
+
|
|
13
|
+
from .._settings import settings_manager
|
|
14
|
+
from .._views.generate_request import GenerateRequest
|
|
15
|
+
from .resolve_generate_params import resolve_generate_params
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def handle_generate(
|
|
19
|
+
ctx: AppContext, req: GenerateRequest
|
|
20
|
+
) -> tuple[JobResult, list[FileID]]:
|
|
21
|
+
spec = model_registry.resolve("audiogen", req.model)
|
|
22
|
+
ctx.ensure_model_ready(spec)
|
|
23
|
+
settings = settings_manager.get_settings()
|
|
24
|
+
params = resolve_generate_params(settings, req, variant=spec.name)
|
|
25
|
+
payload = ctx.memory_manager.acquire(spec)
|
|
26
|
+
result = spec.module.run(payload, params, ctx.file_store)
|
|
27
|
+
return result, [result["file_id"]]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Merge an AudioGen request with settings defaults into GenerateParams."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
|
|
5
|
+
from .._settings import AudiogenSettings
|
|
6
|
+
from .._views.generate_params import GenerateParams
|
|
7
|
+
from .._views.generate_request import GenerateRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def resolve_generate_params(
|
|
11
|
+
settings: AudiogenSettings,
|
|
12
|
+
req: GenerateRequest,
|
|
13
|
+
*,
|
|
14
|
+
variant: str,
|
|
15
|
+
) -> GenerateParams:
|
|
16
|
+
return GenerateParams(
|
|
17
|
+
model=variant,
|
|
18
|
+
prompt=req.prompt,
|
|
19
|
+
duration=req.duration,
|
|
20
|
+
seed=req.seed if req.seed is not None else random.randint(0, 2**31 - 1),
|
|
21
|
+
top_k=req.top_k,
|
|
22
|
+
top_p=req.top_p,
|
|
23
|
+
temperature=req.temperature,
|
|
24
|
+
cfg_coef=req.cfg_coef,
|
|
25
|
+
)
|