"""Pure helpers for the optional CPU image-caption assistant. No clients, credentials, model calls or adapter changes live in this module. """ from __future__ import annotations ECONOMY_SPACE = "amisima/Qwen3.5-Picture-Captioner" ECONOMY_LABEL = "Super Economy - basic description" ECONOMY_TOKENS = 384 ECONOMY_NOTE = ( "Super Economy describes reference images on CPU without using ZeroGPU quota. " "It keeps your idea, LoRAs and strengths. With text alone it keeps your original " "description without an AI call. Use Qwen3.8 for detailed rewriting, translation " "and automatic LoRA choices. Review the small model's image description." ) def is_economy(writer): value = str(writer or "").strip().rstrip("/") for prefix in ("https://huggingface.co/spaces/", "http://huggingface.co/spaces/"): if value.lower().startswith(prefix): value = value[len(prefix):] break return value.casefold() == ECONOMY_SPACE.casefold() def economy_instruction(idea="", kind="video", has_image=True): """Caption only; do not make this small model interpret adapter catalogues.""" if not has_image: raise ValueError("Text-only Economy uses the original idea without an AI call.") return ( "Describe this reference image in one concise English paragraph, at most 70 words. " "Describe the visible subjects, clothes, pose, setting and lighting. " "Only describe what is visible. Do not invent dialogue, movement or extra objects. " "Return only the description, without headings, lists, JSON or settings." ) def economy_prompt(caption, original, controls=""): """Keep the user's exact instructions independently of the model's caption.""" original = str(original or "").strip() caption = str(caption or "").strip() if caption: if caption.startswith(("{", "[")) or any( label in caption.upper() for label in ("STRENGTHS:", "PICKS:") ): raise ValueError("The Economy assistant returned settings instead of an image description.") parts = ["Reference appearance: " + caption] if original: parts.append("Requested action or changes (these take precedence over the reference appearance): " + original) else: parts = [original] if original else [] if controls: parts.append(str(controls)) if not parts: raise ValueError("Enter a description or attach a reference image.") return "\n\n".join(parts) def economy_status(has_image): if has_image: return "Super Economy: image described on CPU. Review the description. Your LoRAs and strengths were kept." return "Super Economy: your original description was kept; no AI call was made. Your LoRAs and strengths were kept."