From 1889e9a2225b9cd356356e49a434760d0abb302d Mon Sep 17 00:00:00 2001 From: zhoujie <929834232@qq.com> Date: Sat, 28 Feb 2026 21:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20Windows=20=E4=B8=8B=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=9D=E5=AD=98=E6=97=B6=E7=9A=84=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 `ConfigManager.save()` 方法中增加重试逻辑,当 `os.replace` 因目标文件被占用而抛出 `PermissionError` 时,最多重试 3 次,每次间隔 0.1 秒 ♻️ refactor(import): 修正模块导入路径 - 在 `LLMService.get_sd_prompt_guide` 方法中,将 `from sd_service import ...` 修正为 `from services.sd_service import ...`,以修复因相对导入路径错误导致的模块未找到问题 🔧 chore(ui): 优化 UI 组件交互性与初始化参数 - 在 `_fn_batch_generate` 函数中,为 `PublishQueue` 实例化明确指定工作空间参数 `"xhs_workspace"` - 在 `tab_create.py` 的封面图策略 `gr.Radio` 组件中,添加 `interactive=True` 参数以启用用户交互 --- services/config_manager.py | 11 ++++++++++- services/llm_service.py | 2 +- ui/app.py | 2 +- ui/tab_create.py | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/services/config_manager.py b/services/config_manager.py index 829a682..4fbd39f 100644 --- a/services/config_manager.py +++ b/services/config_manager.py @@ -95,13 +95,22 @@ class ConfigManager: def save(self): """原子写:临时文件 + os.replace,防止写中断导致数据损坏""" + import time config_dir = os.path.dirname(os.path.abspath(CONFIG_FILE)) or "." try: fd, tmp_path = tempfile.mkstemp(dir=config_dir, suffix=".tmp", prefix="config_") try: with os.fdopen(fd, "w", encoding="utf-8") as f: json.dump(self._config, f, indent=4, ensure_ascii=False) - os.replace(tmp_path, CONFIG_FILE) + # Windows 下目标文件被占用时 os.replace 会抛 PermissionError(WinError 5),重试最多 3 次 + for attempt in range(3): + try: + os.replace(tmp_path, CONFIG_FILE) + break + except PermissionError: + if attempt == 2: + raise + time.sleep(0.1) except Exception: try: os.remove(tmp_path) diff --git a/services/llm_service.py b/services/llm_service.py index 26511dc..ebf33d2 100644 --- a/services/llm_service.py +++ b/services/llm_service.py @@ -370,7 +370,7 @@ class LLMService: @staticmethod def get_sd_prompt_guide(sd_model_name: str = None, persona: str = None) -> str: """根据当前 SD 模型 + 人设 生成 LLM 使用的绘图 Prompt 指南(含反 AI 检测指导 + 人设视觉风格)""" - from sd_service import SD_MODEL_PROFILES, detect_model_profile, get_persona_sd_profile + from services.sd_service import SD_MODEL_PROFILES, detect_model_profile, get_persona_sd_profile key = detect_model_profile(sd_model_name) if sd_model_name else "juggernautXL" profile = SD_MODEL_PROFILES.get(key, SD_MODEL_PROFILES["juggernautXL"]) diff --git a/ui/app.py b/ui/app.py index 6cc6728..b8a968d 100644 --- a/ui/app.py +++ b/ui/app.py @@ -70,7 +70,7 @@ def _fn_topic_recommend(model_name): def _fn_batch_generate(model_name, topics, style, sd_model_name, persona_text, template_name): """批量生成文案并入草稿队列""" - pq = PublishQueue() + pq = PublishQueue("xhs_workspace") return batch_generate_copy( model=model_name, topics=topics, diff --git a/ui/tab_create.py b/ui/tab_create.py index 20ba138..76f0918 100644 --- a/ui/tab_create.py +++ b/ui/tab_create.py @@ -83,6 +83,7 @@ def build_tab( label="封面图策略", value="人物特写", info="影响 SD 构图和尺寸", + interactive=True, ) quality_mode = gr.Radio( sd_preset_names,