"""Model identity and bounded UI inputs; safe to import without torch.""" import math MODEL_ID = "Qwen/Qwen-Image-2.1" MODEL_REVISION = "b3179ad355be050328e483a9dfdd9e60cd62adfa" DIFFUSERS_REVISION = "80c7ed262aeffbeb43ef13ae04baeb9b84515a69" MAX_SEED = 2**32 - 1 MAX_PROMPT_CHARS = 4000 MAX_REFERENCE_PIXELS = 20_000_000 STEPS = {"Draft · 20 steps": 20, "Balanced · 30 steps": 30, "Full · 40 steps": 40} DEFAULT_QUALITY = "Balanced · 30 steps" # Curated examples keep their original settings and cached recipe semantics. EXAMPLE_QUALITY = "Full · 40 steps" def duration_cap(steps, output_resolution, has_reference, gpu_size="xlarge"): """Scheduled seconds, with >=40% margin over measured mode maxima. Conservative per-mode caps include measured decorator overhead. They are requests to ZeroGPU, not guaranteed latency or a platform quota balance. """ if output_resolution >= 2048: seconds = (45 + 1.875 * steps) if has_reference else (30 + 1.375 * steps) else: seconds = 20 + 0.25 * steps # 25 / 27.5 / 30; cold/long-prompt margin return math.ceil(seconds * (1 if gpu_size == "xlarge" else 2.2)) SIZES = { "1K": { "1:1": (1024, 1024), "4:3": (1184, 896), "3:4": (896, 1184), "16:9": (1376, 768), "9:16": (768, 1376), }, "2K": { "1:1": (2048, 2048), "4:3": (2400, 1792), "3:4": (1792, 2400), "16:9": (2752, 1536), "9:16": (1536, 2752), }, } EXAMPLE_PROMPTS = [ 'Editorial still life of a single cobalt-blue glass pear on a warm ivory plinth. ' 'Hard afternoon sunlight from the left, a long precise shadow, subtle glass caustics, ' 'tactile matte background, spare composition, fine-art studio photograph.', 'A beautifully typeset exhibition poster. Large black text reads "SLOW SUNDAY" ' 'on two lines, small text below reads "20 SEPTEMBER". A single red circle in the ' 'lower right. Warm white paper, Swiss typography, generous margins, flat front view.', 'A quiet coastal house in pale limestone above the sea, a linen curtain moving ' 'in an open doorway, an olive tree casting dappled shadows, late afternoon ' 'Mediterranean light, architectural photograph, natural materials, no people.', 'A small charming origami crane made of textured vermilion paper, folded edges ' 'clearly visible, isolated centered object, soft studio light, no text.', ] def validate_inputs(prompt, quality, resolution, aspect, seed): if not isinstance(prompt, str) or not prompt.strip(): raise ValueError("Describe the image you would like to make.") if len(prompt) > MAX_PROMPT_CHARS: raise ValueError(f"Keep your description to {MAX_PROMPT_CHARS:,} characters or fewer.") if quality not in STEPS or resolution not in SIZES or aspect not in SIZES[resolution]: raise ValueError("Choose one of the available quality, size, and shape options.") if isinstance(seed, bool) or not isinstance(seed, (int, float)): raise ValueError("Seed must be a whole number.") if not math.isfinite(seed) or seed != int(seed) or not 0 <= seed <= MAX_SEED: raise ValueError(f"Seed must be a whole number from 0 to {MAX_SEED}.") return prompt.strip(), STEPS[quality], SIZES[resolution][aspect], int(seed) def effective_prompt(prompt, transparent): if transparent: return ( "This is an RGBA image with transparency. " + prompt + " The image has alpha channel and the background is transparent." ) return prompt