feat(gui): replace AI studio with product suite

This commit is contained in:
chengma
2026-07-14 09:53:13 +08:00
parent fb873aae90
commit bc115ba0d7
27 changed files with 3453 additions and 81 deletions
+28 -3
View File
@@ -13,6 +13,7 @@ from .version import APP_VERSION
MAX_CMHUB_IMAGE_STUDIO_WORKERS = 5
_GLOBAL_IMAGE_STUDIO_SLOTS = threading.BoundedSemaphore(MAX_CMHUB_IMAGE_STUDIO_WORKERS)
class ImageStudioGenerationError(RuntimeError):
@@ -171,7 +172,7 @@ def run_jobs(
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {
executor.submit(
_run_one_job,
_run_one_job_with_global_slot,
job.id,
runtime,
cfg,
@@ -206,6 +207,11 @@ def run_jobs(
return summary
def _run_one_job_with_global_slot(*args):
with _GLOBAL_IMAGE_STUDIO_SLOTS:
return _run_one_job(*args)
def _run_one_job(job_id, runtime, config, image_root, aspect_ratio, db_path, should_stop, on_event):
job = image_studio.get_job(job_id, path=db_path)
if job is None:
@@ -237,14 +243,24 @@ def _run_one_job(job_id, runtime, config, image_root, aspect_ratio, db_path, sho
source_asset,
runtime,
config,
aspect_ratio,
db_path,
should_stop,
on_event,
)
image_studio.update_job_status(job.id, "running", path=db_path)
request_result = _poll_job(job.id, request_result["task_id"], runtime, request_result, db_path, should_stop, on_event)
_raise_if_stopped(should_stop)
out_path = _output_path(project, job, image_root)
saved_path = _download_and_save_job_image(request_result, out_path, config, on_event, job.id)
try:
_raise_if_stopped(should_stop)
except ImageStudioGenerationError:
try:
if os.path.isfile(saved_path):
os.remove(saved_path)
finally:
raise
asset = image_studio.add_asset(
project.id,
_generated_kind(job.job_type),
@@ -278,7 +294,16 @@ def _run_one_job(job_id, runtime, config, image_root, aspect_ratio, db_path, sho
return {"job": updated, "status": status, "error": str(exc)}
def _submit_or_resume_job(job, source_asset, runtime, config, db_path, should_stop, on_event):
def _submit_or_resume_job(
job,
source_asset,
runtime,
config,
aspect_ratio,
db_path,
should_stop,
on_event,
):
if job.task_id:
_notify(on_event, {"job_id": job.id, "step": "cover_request", "result": "resume", "task_id": job.task_id})
return _request_result(job.task_id, runtime, config)
@@ -291,7 +316,7 @@ def _submit_or_resume_job(job, source_asset, runtime, config, db_path, should_st
"model": runtime["alias"],
"image_base64": ai._image_data_url(source_path),
"resolution": ai._normalize_cmhub_resolution(resolution),
"aspect_ratio": "1:1",
"aspect_ratio": str(aspect_ratio or "1:1"),
}
_notify(on_event, {"job_id": job.id, "step": "cover_submit", "result": "start"})
data = ai._cmhub_call_with_retry(