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,260 @@
|
|
|
1
|
+
# flux2
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **日本語**
|
|
4
|
+
|
|
5
|
+
[mflux FLUX.2 Klein](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/flux2/README.md) で、画像生成・画像編集・LoRA 学習機能を提供します。
|
|
6
|
+
|
|
7
|
+
- **generate**:
|
|
8
|
+
- txt2img / img2img
|
|
9
|
+
- **edit**:
|
|
10
|
+
- Files API の 1 枚以上の参照画像を使う複数参照編集
|
|
11
|
+
- **train**:
|
|
12
|
+
- 自前データセット ZIP から LoRA アダプタを学習
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
| Endpoint | Name | Description |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `POST /v1/image/flux2/generate` | 画像生成 | プロンプトから画像を生成。`init_image` FileRef がある場合は img2img。 |
|
|
19
|
+
| `POST /v1/image/flux2/edit` | 画像編集 | Files API の `images` FileRef 配列を参照画像として編集。 |
|
|
20
|
+
| `POST /v1/image/flux2/train` | LoRA 学習 | データセット ZIP から LoRA アダプタを学習。**常に async**。 |
|
|
21
|
+
| `GET /v1/image/flux2/models` | モデル一覧 | 利用可能なモデルの一覧を返す。 |
|
|
22
|
+
| `GET /v1/image/flux2/openapi.json` | OpenAPI | 詳細な入出力仕様、使い方、TIPS を返す。 |
|
|
23
|
+
|
|
24
|
+
## API Docs
|
|
25
|
+
|
|
26
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/image/flux2/openapi.json)
|
|
27
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/image/flux2/docs.html)
|
|
28
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/image/flux2/redoc.html)
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
| Package | License | Description |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| [mflux](https://github.com/filipstrand/mflux) | MIT | FLUX.2 Klein の生成・編集・LoRA 学習を MLX 上で実行。 |
|
|
35
|
+
|
|
36
|
+
## Models
|
|
37
|
+
|
|
38
|
+
| Model | License | Terms | Size | Description |
|
|
39
|
+
|---|---|---|---:|---|
|
|
40
|
+
| [black-forest-labs/FLUX.2-klein-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-9B) | FLUX Non-Commercial License | 要 | 52.9 GB | `klein-9b`(デフォルト)。少ステップ向けの 9B Klein。既定は `steps: 4`、`guidance: 1.0`、`quantize: null`。生成・編集に使える。 |
|
|
41
|
+
| [black-forest-labs/FLUX.2-klein-base-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B) | Apache-2.0 | 不要 | 23.7 GB | `klein-base-4b`。base variant。既定は `steps: 40`、`guidance: 1.0`、`quantize: 8`。生成・編集・LoRA 学習に使える。 |
|
|
42
|
+
| [black-forest-labs/FLUX.2-klein-base-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-9B) | FLUX Non-Commercial License | 要 | 52.9 GB | `klein-base-9b`。base variant。既定は `steps: 40`、`guidance: 1.0`、`quantize: 8`。生成・編集・LoRA 学習に使える。 |
|
|
43
|
+
|
|
44
|
+
## Notes
|
|
45
|
+
|
|
46
|
+
- **サイズ制約**:
|
|
47
|
+
`width` / `height` は 16 の倍数。既定は `1024 x 1024`、上限は `2048 x 2048`。
|
|
48
|
+
`steps` の上限は `100`。
|
|
49
|
+
- **LoRA 適用**:
|
|
50
|
+
`loras: [{"file": {"type": "file_id", "file_id": "..."}, "scale": 1.0}]` で学習済みアダプタを適用する。
|
|
51
|
+
最大 4 つまで。`scale` は効きの強さ。
|
|
52
|
+
- **LoRA 学習データセット**:
|
|
53
|
+
ZIP は画像をトップレベル、または単一サブフォルダに入れる。
|
|
54
|
+
`training_mode: "text"` では各画像に同じ語幹の `.txt` キャプションが必要。
|
|
55
|
+
`training_mode: "edit"` では `*_in.*` / `*_out.*` の画像ペアと `*_in.txt` プロンプトが必要。
|
|
56
|
+
- **メモリ目安**:
|
|
57
|
+
`klein-9b` は約 29 GiB、edit では約 31.6 GiB のピーク実測。
|
|
58
|
+
`klein-base-4b` は q8 / 512 / 40 steps で約 9.1 GiB、
|
|
59
|
+
`klein-base-9b` は約 16.8 GiB。train は `KIAPI_FLUX2_TRAIN_RESERVE_GB`
|
|
60
|
+
既定 24 GiB を予約する。
|
|
61
|
+
|
|
62
|
+
## Quickstart
|
|
63
|
+
|
|
64
|
+
### generate — txt2img
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
jq -n \
|
|
68
|
+
'{
|
|
69
|
+
model: "klein-9b",
|
|
70
|
+
mode: "sync",
|
|
71
|
+
prompt: "a cafe storefront, a sign clearly reads CAFE, bright daylight",
|
|
72
|
+
width: 512,
|
|
73
|
+
height: 512,
|
|
74
|
+
seed: 1
|
|
75
|
+
}' |
|
|
76
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
77
|
+
-H 'Content-Type: application/json' \
|
|
78
|
+
--data-binary @- \
|
|
79
|
+
-o flux2.png
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Job JSON が欲しい場合:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
jq -n \
|
|
86
|
+
'{
|
|
87
|
+
model: "klein-9b",
|
|
88
|
+
mode: "sync",
|
|
89
|
+
prompt: "a small robot watering flowers, clean studio illustration",
|
|
90
|
+
width: 512,
|
|
91
|
+
height: 512,
|
|
92
|
+
seed: 2
|
|
93
|
+
}' |
|
|
94
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
95
|
+
-H 'Accept: application/json' \
|
|
96
|
+
-H 'Content-Type: application/json' \
|
|
97
|
+
--data-binary @- |
|
|
98
|
+
jq .
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### generate — img2img
|
|
102
|
+
|
|
103
|
+
先にソース画像をアップロードする:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
IMG=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
107
|
+
-F "file=@source.png" | jq -r .file_id)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
jq -n \
|
|
112
|
+
--arg img "$IMG" \
|
|
113
|
+
'{
|
|
114
|
+
model: "klein-9b",
|
|
115
|
+
mode: "sync",
|
|
116
|
+
prompt: "turn this into a polished cozy illustration",
|
|
117
|
+
init_image: {type: "file_id", file_id: $img},
|
|
118
|
+
image_strength: 0.45,
|
|
119
|
+
width: 1024,
|
|
120
|
+
height: 576,
|
|
121
|
+
seed: 7
|
|
122
|
+
}' |
|
|
123
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
124
|
+
-H 'Content-Type: application/json' \
|
|
125
|
+
--data-binary @- \
|
|
126
|
+
-o flux2-img2img.png
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`image_strength` は 0-1。小さいほど入力画像を強く残し、大きいほどプロンプト側に寄る。
|
|
130
|
+
|
|
131
|
+
### edit — 複数参照画像での編集
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
REF1=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
135
|
+
-F "file=@mascot.png" | jq -r .file_id)
|
|
136
|
+
REF2=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
137
|
+
-F "file=@object.png" | jq -r .file_id)
|
|
138
|
+
|
|
139
|
+
jq -n \
|
|
140
|
+
--arg ref1 "$REF1" \
|
|
141
|
+
--arg ref2 "$REF2" \
|
|
142
|
+
'{
|
|
143
|
+
model: "klein-9b",
|
|
144
|
+
mode: "sync",
|
|
145
|
+
prompt: "make a playful illustration combining the mascot and object",
|
|
146
|
+
images: [{type: "file_id", file_id: $ref1}, {type: "file_id", file_id: $ref2}],
|
|
147
|
+
width: 1024,
|
|
148
|
+
height: 576,
|
|
149
|
+
seed: 9
|
|
150
|
+
}' |
|
|
151
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/edit \
|
|
152
|
+
-H 'Content-Type: application/json' \
|
|
153
|
+
--data-binary @- \
|
|
154
|
+
-o flux2-edit.png
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### async
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
JOB=$(
|
|
161
|
+
jq -n \
|
|
162
|
+
'{
|
|
163
|
+
model: "klein-9b",
|
|
164
|
+
mode: "async",
|
|
165
|
+
prompt: "a cinematic product photo of a glass teapot",
|
|
166
|
+
width: 512,
|
|
167
|
+
height: 512,
|
|
168
|
+
seed: 11
|
|
169
|
+
}' |
|
|
170
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
171
|
+
-H 'Accept: application/json' \
|
|
172
|
+
-H 'Content-Type: application/json' \
|
|
173
|
+
--data-binary @- |
|
|
174
|
+
jq -r .job_id
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
完了後、Job の `artifacts[0]` または `result.file_id` を使って画像を取得する:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
FID=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.file_id)
|
|
184
|
+
curl -sS http://localhost:${PORT:-8000}/v1/files/$FID/download -o flux2-async.png
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### train — LoRA
|
|
188
|
+
|
|
189
|
+
`training_mode: "text"` のデータセット例:
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
my_lora/
|
|
193
|
+
sample_01.png
|
|
194
|
+
sample_01.txt
|
|
195
|
+
sample_02.png
|
|
196
|
+
sample_02.txt
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
データセット ZIP を作り、Files API にアップロードする:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
(cd my_lora && zip -q -r - .) > dataset.zip
|
|
203
|
+
|
|
204
|
+
DS=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
205
|
+
-F "file=@dataset.zip" | jq -r .file_id)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
学習を開始する。train は常に async:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
JOB=$(
|
|
212
|
+
jq -n \
|
|
213
|
+
--arg ds "$DS" \
|
|
214
|
+
'{
|
|
215
|
+
model: "klein-base-4b",
|
|
216
|
+
dataset: {type: "file_id", file_id: $ds},
|
|
217
|
+
training_mode: "text",
|
|
218
|
+
num_epochs: 10,
|
|
219
|
+
lora_rank: 8
|
|
220
|
+
}' |
|
|
221
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/train \
|
|
222
|
+
-H 'Content-Type: application/json' \
|
|
223
|
+
--data-binary @- |
|
|
224
|
+
jq -r .job_id
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
echo "$JOB"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
完了までポーリングし、学習済みアダプタの `file_id` を取得する:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
until STATUS=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .status) && \
|
|
234
|
+
[ "$STATUS" != "queued" ] && [ "$STATUS" != "running" ]; do
|
|
235
|
+
sleep 5
|
|
236
|
+
done
|
|
237
|
+
|
|
238
|
+
ADAPTER=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.adapter_file_id)
|
|
239
|
+
echo "$ADAPTER"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 学習済み LoRA で生成
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
jq -n \
|
|
246
|
+
--arg adapter "$ADAPTER" \
|
|
247
|
+
'{
|
|
248
|
+
model: "klein-base-4b",
|
|
249
|
+
mode: "sync",
|
|
250
|
+
prompt: "<your trigger word> as a clean editorial illustration",
|
|
251
|
+
width: 512,
|
|
252
|
+
height: 512,
|
|
253
|
+
seed: 13,
|
|
254
|
+
loras: [{file: {type: "file_id", file_id: $adapter}, scale: 1.0}]
|
|
255
|
+
}' |
|
|
256
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
257
|
+
-H 'Content-Type: application/json' \
|
|
258
|
+
--data-binary @- \
|
|
259
|
+
-o flux2-lora.png
|
|
260
|
+
```
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# flux2
|
|
2
|
+
|
|
3
|
+
**English** | [日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
[mflux FLUX.2 Klein](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/flux2/README.md) provides image generation, image editing, and LoRA learning functions.
|
|
6
|
+
|
|
7
|
+
- **generate**:
|
|
8
|
+
- txt2img / img2img
|
|
9
|
+
- **edit**:
|
|
10
|
+
- Multi-reference editing using one or more reference images from the Files API
|
|
11
|
+
- **train**:
|
|
12
|
+
- Learn LoRA adapter from your own dataset ZIP
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
| Endpoint | Name | Description |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `POST /v1/image/flux2/generate` | Image generation | Generate image from prompt. `init_image` img2img if FileRef exists. |
|
|
19
|
+
| `POST /v1/image/flux2/edit` | Image editing | Edit the `images` FileRef array of Files API as a reference image. |
|
|
20
|
+
| `POST /v1/image/flux2/train` | LoRA learning | Learn LoRA adapter from dataset ZIP. **Always async**. |
|
|
21
|
+
| `GET /v1/image/flux2/models` | List of models | Return the list of available models. |
|
|
22
|
+
| `GET /v1/image/flux2/openapi.json` | OpenAPI | Returns detailed input/output specifications, usage, and TIPS. |
|
|
23
|
+
|
|
24
|
+
## API Docs
|
|
25
|
+
|
|
26
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/image/flux2/openapi.json)
|
|
27
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/image/flux2/docs.html)
|
|
28
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/image/flux2/redoc.html)
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
| Package | License | Description |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| [mflux](https://github.com/filipstrand/mflux) | MIT | FLUX.2 Execute Klein generation, editing, and LoRA learning on MLX. |
|
|
35
|
+
|
|
36
|
+
## Models
|
|
37
|
+
|
|
38
|
+
| Model | License | Terms | Size | Description |
|
|
39
|
+
|---|---|---|---:|---|
|
|
40
|
+
| [black-forest-labs/FLUX.2-klein-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-9B) | FLUX Non-Commercial License | Required | 52.9 GB | `klein-9b` (default). 9B Klein for small steps. Defaults are `steps: 4`, `guidance: 1.0`, `quantize: null`. Can be used for generation and editing. |
|
|
41
|
+
| [black-forest-labs/FLUX.2-klein-base-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B) | Apache-2.0 | Not required | 23.7 GB | `klein-base-4b`. base variant. Defaults are `steps: 40`, `guidance: 1.0`, `quantize: 8`. Can be used for generation, editing, and LoRA learning. |
|
|
42
|
+
| [black-forest-labs/FLUX.2-klein-base-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-9B) | FLUX Non-Commercial License | Required | 52.9 GB | `klein-base-9b`. base variant. Defaults are `steps: 40`, `guidance: 1.0`, `quantize: 8`. Can be used for generation, editing, and LoRA learning. |
|
|
43
|
+
|
|
44
|
+
## Notes
|
|
45
|
+
|
|
46
|
+
- **Size constraints**:
|
|
47
|
+
`width` / `height` are multiples of 16. Default is `1024 x 1024`, upper limit is `2048 x 2048`.
|
|
48
|
+
The upper limit of `steps` is `100`.
|
|
49
|
+
- **LoRA applied**:
|
|
50
|
+
Apply the learned adapter with `loras: [{"file": {"type": "file_id", "file_id": "..."}, "scale": 1.0}]`.
|
|
51
|
+
Up to 4. `scale` is the strength of the effect.
|
|
52
|
+
- **LoRA training dataset**:
|
|
53
|
+
ZIP puts images into a top-level or single subfolder.
|
|
54
|
+
`training_mode: "text"` requires each image to have a `.txt` caption with the same stem.
|
|
55
|
+
`training_mode: "edit"` requires `*_in.*` / `*_out.*` image pairs and `*_in.txt` prompt.
|
|
56
|
+
- **Memory guideline**:
|
|
57
|
+
`klein-9b` has a peak measurement of about 29 GiB, and edit has a peak measurement of about 31.6 GiB.
|
|
58
|
+
`klein-base-4b` is about 9.1 GiB with q8 / 512 / 40 steps,
|
|
59
|
+
`klein-base-9b` is approximately 16.8 GiB. train is `KIAPI_FLUX2_TRAIN_RESERVE_GB`
|
|
60
|
+
Reserve default 24 GiB.
|
|
61
|
+
|
|
62
|
+
## Quickstart
|
|
63
|
+
|
|
64
|
+
### generate — txt2img
|
|
65
|
+
```bash
|
|
66
|
+
jq -n \
|
|
67
|
+
'{
|
|
68
|
+
model: "klein-9b",
|
|
69
|
+
mode: "sync",
|
|
70
|
+
prompt: "a cafe storefront, a sign clearly reads CAFE, bright daylight",
|
|
71
|
+
width: 512,
|
|
72
|
+
height: 512,
|
|
73
|
+
seed: 1
|
|
74
|
+
}' |
|
|
75
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
76
|
+
-H 'Content-Type: application/json' \
|
|
77
|
+
--data-binary @- \
|
|
78
|
+
-o flux2.png
|
|
79
|
+
```
|
|
80
|
+
If you want Job JSON:
|
|
81
|
+
```bash
|
|
82
|
+
jq -n \
|
|
83
|
+
'{
|
|
84
|
+
model: "klein-9b",
|
|
85
|
+
mode: "sync",
|
|
86
|
+
prompt: "a small robot watering flowers, clean studio illustration",
|
|
87
|
+
width: 512,
|
|
88
|
+
height: 512,
|
|
89
|
+
seed: 2
|
|
90
|
+
}' |
|
|
91
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
92
|
+
-H 'Accept: application/json' \
|
|
93
|
+
-H 'Content-Type: application/json' \
|
|
94
|
+
--data-binary @- |
|
|
95
|
+
jq .
|
|
96
|
+
```
|
|
97
|
+
### generate — img2img
|
|
98
|
+
|
|
99
|
+
Upload the source image first:
|
|
100
|
+
```bash
|
|
101
|
+
IMG=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
102
|
+
-F "file=@source.png" | jq -r .file_id)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
jq -n \
|
|
107
|
+
--arg img "$IMG" \
|
|
108
|
+
'{
|
|
109
|
+
model: "klein-9b",
|
|
110
|
+
mode: "sync",
|
|
111
|
+
prompt: "turn this into a polished cozy illustration",
|
|
112
|
+
init_image: {type: "file_id", file_id: $img},
|
|
113
|
+
image_strength: 0.45,
|
|
114
|
+
width: 1024,
|
|
115
|
+
height: 576,
|
|
116
|
+
seed: 7
|
|
117
|
+
}' |
|
|
118
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
119
|
+
-H 'Content-Type: application/json' \
|
|
120
|
+
--data-binary @- \
|
|
121
|
+
-o flux2-img2img.png
|
|
122
|
+
```
|
|
123
|
+
`image_strength` is 0-1. The smaller the value, the stronger the input image remains, and the larger the value, the closer it is to the prompt side.
|
|
124
|
+
|
|
125
|
+
### edit — Editing with multiple reference images
|
|
126
|
+
```bash
|
|
127
|
+
REF1=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
128
|
+
-F "file=@mascot.png" | jq -r .file_id)
|
|
129
|
+
REF2=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
130
|
+
-F "file=@object.png" | jq -r .file_id)
|
|
131
|
+
|
|
132
|
+
jq -n \
|
|
133
|
+
--arg ref1 "$REF1" \
|
|
134
|
+
--arg ref2 "$REF2" \
|
|
135
|
+
'{
|
|
136
|
+
model: "klein-9b",
|
|
137
|
+
mode: "sync",
|
|
138
|
+
prompt: "make a playful illustration combining the mascot and object",
|
|
139
|
+
images: [{type: "file_id", file_id: $ref1}, {type: "file_id", file_id: $ref2}],
|
|
140
|
+
width: 1024,
|
|
141
|
+
height: 576,
|
|
142
|
+
seed: 9
|
|
143
|
+
}' |
|
|
144
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/edit \
|
|
145
|
+
-H 'Content-Type: application/json' \
|
|
146
|
+
--data-binary @- \
|
|
147
|
+
-o flux2-edit.png
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### async
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
JOB=$(
|
|
154
|
+
jq -n \
|
|
155
|
+
'{
|
|
156
|
+
model: "klein-9b",
|
|
157
|
+
mode: "async",
|
|
158
|
+
prompt: "a cinematic product photo of a glass teapot",
|
|
159
|
+
width: 512,
|
|
160
|
+
height: 512,
|
|
161
|
+
seed: 11
|
|
162
|
+
}' |
|
|
163
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
164
|
+
-H 'Accept: application/json' \
|
|
165
|
+
-H 'Content-Type: application/json' \
|
|
166
|
+
--data-binary @- |
|
|
167
|
+
jq -r .job_id
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
171
|
+
```
|
|
172
|
+
Once completed, use the Job's `artifacts[0]` or `result.file_id` to get the image:
|
|
173
|
+
```bash
|
|
174
|
+
FID=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.file_id)
|
|
175
|
+
curl -sS http://localhost:${PORT:-8000}/v1/files/$FID/download -o flux2-async.png
|
|
176
|
+
```
|
|
177
|
+
### train — LoRA
|
|
178
|
+
|
|
179
|
+
Example dataset for `training_mode: "text"`:
|
|
180
|
+
```text
|
|
181
|
+
my_lora/
|
|
182
|
+
sample_01.png
|
|
183
|
+
sample_01.txt
|
|
184
|
+
sample_02.png
|
|
185
|
+
sample_02.txt
|
|
186
|
+
```
|
|
187
|
+
Create a dataset ZIP and upload it to the Files API:
|
|
188
|
+
```bash
|
|
189
|
+
(cd my_lora && zip -q -r - .) > dataset.zip
|
|
190
|
+
|
|
191
|
+
DS=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
192
|
+
-F "file=@dataset.zip" | jq -r .file_id)
|
|
193
|
+
```
|
|
194
|
+
Start learning. train is always async:
|
|
195
|
+
```bash
|
|
196
|
+
JOB=$(
|
|
197
|
+
jq -n \
|
|
198
|
+
--arg ds "$DS" \
|
|
199
|
+
'{
|
|
200
|
+
model: "klein-base-4b",
|
|
201
|
+
dataset: {type: "file_id", file_id: $ds},
|
|
202
|
+
training_mode: "text",
|
|
203
|
+
num_epochs: 10,
|
|
204
|
+
lora_rank: 8
|
|
205
|
+
}' |
|
|
206
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/train \
|
|
207
|
+
-H 'Content-Type: application/json' \
|
|
208
|
+
--data-binary @- |
|
|
209
|
+
jq -r .job_id
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
echo "$JOB"
|
|
213
|
+
```
|
|
214
|
+
Poll until completion and get the learned adapter's `file_id`:
|
|
215
|
+
```bash
|
|
216
|
+
until STATUS=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .status) && \
|
|
217
|
+
[ "$STATUS" != "queued" ] && [ "$STATUS" != "running" ]; do
|
|
218
|
+
sleep 5
|
|
219
|
+
done
|
|
220
|
+
|
|
221
|
+
ADAPTER=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.adapter_file_id)
|
|
222
|
+
echo "$ADAPTER"
|
|
223
|
+
```
|
|
224
|
+
### Generated with trained LoRA
|
|
225
|
+
```bash
|
|
226
|
+
jq -n \
|
|
227
|
+
--arg adapter "$ADAPTER" \
|
|
228
|
+
'{
|
|
229
|
+
model: "klein-base-4b",
|
|
230
|
+
mode: "sync",
|
|
231
|
+
prompt: "<your trigger word> as a clean editorial illustration",
|
|
232
|
+
width: 512,
|
|
233
|
+
height: 512,
|
|
234
|
+
seed: 13,
|
|
235
|
+
loras: [{file: {type: "file_id", file_id: $adapter}, scale: 1.0}]
|
|
236
|
+
}' |
|
|
237
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/flux2/generate \
|
|
238
|
+
-H 'Content-Type: application/json' \
|
|
239
|
+
--data-binary @- \
|
|
240
|
+
-o flux2-lora.png
|
|
241
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""flux2 family — FLUX.2 Klein generation/edit/LoRA-training via mflux.
|
|
2
|
+
|
|
3
|
+
Endpoints: ``POST /v1/image/flux2/{generate,edit,train}``. ``generate`` is
|
|
4
|
+
text-to-image (img2img when ``init_image_file_id`` is supplied), ``edit`` is
|
|
5
|
+
multi-reference image editing, and ``train`` LoRA-finetunes base variants on
|
|
6
|
+
captioned images or ``*_in`` / ``*_out`` edit pairs (always async). LoRA adapters
|
|
7
|
+
and a ``quantize`` override run on a one-off transient model; otherwise the
|
|
8
|
+
resident model is used.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from kiapi.capabilities import ValidationError
|
|
12
|
+
|
|
13
|
+
from ._helpers.register import register
|
|
14
|
+
from ._helpers.validate_edit import validate_edit
|
|
15
|
+
from ._helpers.validate_generate import validate_generate
|
|
16
|
+
from ._operations.handle_edit import handle_edit
|
|
17
|
+
from ._operations.handle_generate import handle_generate
|
|
18
|
+
from ._operations.handle_train import handle_train
|
|
19
|
+
from ._settings import settings_manager
|
|
20
|
+
from ._views.edit_request import EditRequest
|
|
21
|
+
from ._views.generate_request import GenerateRequest
|
|
22
|
+
from ._views.train_request import TrainRequest
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"EditRequest", # ._views
|
|
26
|
+
"GenerateRequest", # ._views
|
|
27
|
+
"TrainRequest", # ._views
|
|
28
|
+
"ValidationError", # kiapi.capabilities
|
|
29
|
+
"handle_edit", # ._operations
|
|
30
|
+
"handle_generate", # ._operations
|
|
31
|
+
"handle_train", # ._operations
|
|
32
|
+
"register", # ._helpers
|
|
33
|
+
"settings_manager", # ._settings
|
|
34
|
+
"validate_edit", # ._helpers
|
|
35
|
+
"validate_generate", # ._helpers
|
|
36
|
+
]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
DESCRIPTION = """Image generation, editing, and LoRA training (FLUX.2 Klein via mflux).
|
|
2
|
+
|
|
3
|
+
Three operations on Black Forest Labs' FLUX.2 Klein models: `/generate`
|
|
4
|
+
(text-to-image, or image-to-image when `init_image` is supplied), `/edit`
|
|
5
|
+
(multi-reference image editing), and `/train` (LoRA finetune).
|
|
6
|
+
|
|
7
|
+
## Upstream docs
|
|
8
|
+
- [mflux — FLUX.2](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/flux2/README.md) — the MLX engine kiapi runs
|
|
9
|
+
- [FLUX.2-klein-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-9B) — distilled `klein-9b` weights
|
|
10
|
+
- [FLUX.2-klein-base-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B) / [base-9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-9B) — trainable base weights
|
|
11
|
+
|
|
12
|
+
## Models
|
|
13
|
+
- **klein-9b** (default) — distilled. Fast, few steps (default 4), unquantized.
|
|
14
|
+
The everyday choice for generate/edit.
|
|
15
|
+
- **klein-base-4b** — base. Slower (default 40 steps, q8) but trainable; the
|
|
16
|
+
default `/train` target.
|
|
17
|
+
- **klein-base-9b** — base. Highest quality of the three, slowest; also trainable.
|
|
18
|
+
|
|
19
|
+
Pick the variant with `model` (aliases like `flux2-klein-9b` are accepted);
|
|
20
|
+
discover variants at `GET /v1/image/flux2/models`. Variant-dependent defaults
|
|
21
|
+
(`steps` / `guidance` / `quantize`) are filled in server-side when omitted, and
|
|
22
|
+
the resolved values are recorded in the result `params`. Only base variants are
|
|
23
|
+
trainable — `klein-9b` is rejected by `/train`.
|
|
24
|
+
|
|
25
|
+
## generate vs edit
|
|
26
|
+
- **generate** is text-to-image; pass `init_image` (+ optional `image_strength`)
|
|
27
|
+
to seed an img2img run from one image.
|
|
28
|
+
- **edit** takes a list of reference `images` for multi-reference editing /
|
|
29
|
+
composition under a single prompt.
|
|
30
|
+
|
|
31
|
+
## Resident vs transient runs
|
|
32
|
+
The warmed, resident model uses the server-default quantization. A request that
|
|
33
|
+
either supplies `loras` or sets a `quantize` differing from the resident model
|
|
34
|
+
builds a **one-off transient model** for that call — weights load fresh, so it is
|
|
35
|
+
slower and not reused. For the fast path, omit `loras` and leave `quantize` unset.
|
|
36
|
+
|
|
37
|
+
## LoRA workflow
|
|
38
|
+
Train an adapter via `/train` (always async, base variants only), then apply it on
|
|
39
|
+
`/generate` or `/edit` by passing its `file` id in `loras` (up to 4, each
|
|
40
|
+
`{file, scale}`). The dataset is a ZIP uploaded to the Files API; its layout
|
|
41
|
+
depends on `training_mode`.
|
|
42
|
+
|
|
43
|
+
**`training_mode=text`** — each image has a same-stem `.txt` caption:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
dataset.zip
|
|
47
|
+
├── cat_01.png # image
|
|
48
|
+
├── cat_01.txt # same-stem caption: "a photo of a tabby cat"
|
|
49
|
+
├── cat_02.jpg
|
|
50
|
+
└── cat_02.txt
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**`training_mode=edit`** — `*_in.*` / `*_out.*` image pairs, the `*_in.txt`
|
|
54
|
+
holding the edit prompt:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
dataset.zip
|
|
58
|
+
├── 01_in.png # source image
|
|
59
|
+
├── 01_in.txt # edit prompt: "make it snow"
|
|
60
|
+
├── 01_out.png # target image
|
|
61
|
+
├── 02_in.jpg
|
|
62
|
+
├── 02_in.txt
|
|
63
|
+
└── 02_out.jpg
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## TIPS
|
|
67
|
+
- For a quick image, call `sync` without `Accept: application/json` to get the
|
|
68
|
+
raw bytes straight back (`curl -o out.png`).
|
|
69
|
+
- `width`/`height` must be multiples of 16 and at most 2048x2048 (default 1024).
|
|
70
|
+
- `klein-9b` is the fast default; reach for the base variants only when you need
|
|
71
|
+
their quality or want to train.
|
|
72
|
+
- First use downloads the FLUX.2 weights; run `kiapi activate` ahead of time to
|
|
73
|
+
avoid a cold-start download on the first request.
|
|
74
|
+
|
|
75
|
+
## Performance
|
|
76
|
+
- **klein-9b**: ~29 GiB peak RSS for 512 text/img2img, ~31.6 GiB for edit.
|
|
77
|
+
- **klein-base-4b**: ~9.1 GiB peak at q8/512/40 steps.
|
|
78
|
+
- **klein-base-9b**: ~16.8 GiB peak at q8/512/40 steps.
|
|
79
|
+
- Transient runs (any `loras` or a `quantize` override) rebuild the model each
|
|
80
|
+
call and are slower than the resident path.
|
|
81
|
+
"""
|