Commit ·
b8b444b
1
Parent(s): 3bda1a9
feat: add weight to model/
Browse files- inference.py +105 -0
inference.py
CHANGED
|
@@ -216,6 +216,111 @@ DECISION LOGIC
|
|
| 216 |
- **Unsuitable**: If text is hard to read due to low contrast, complex background interference, or placement in dead zones.
|
| 217 |
- **Suitable**: If text is instantly readable due to clean placement, professional contrast treatments (masks/shadows), or if it is a cinematic still.
|
| 218 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
# ==========================================
|
| 221 |
# 辅助函数
|
|
|
|
| 216 |
- **Unsuitable**: If text is hard to read due to low contrast, complex background interference, or placement in dead zones.
|
| 217 |
- **Suitable**: If text is instantly readable due to clean placement, professional contrast treatments (masks/shadows), or if it is a cinematic still.
|
| 218 |
"""
|
| 219 |
+
##文字-样式数量
|
| 220 |
+
FONT_CONSISTENCY_SYSTEM_PROMPT = """You are a highly critical Senior Art Director and Visual Auditor.
|
| 221 |
+
Your task is to evaluate "Font Style Consistency" to ensure typographic purity and minimize visual noise.
|
| 222 |
+
You have ZERO TOLERANCE for "Font Fatigue" caused by excessive font types.
|
| 223 |
+
|
| 224 |
+
INPUT: One image and one natural-language question about typography.
|
| 225 |
+
|
| 226 |
+
YOUR TASK:
|
| 227 |
+
1. Audit the main text (Headlines, Body) and ignore logos or product packaging text.
|
| 228 |
+
2. Identify and Count the distinct font categories used based on the 4 definitions below.
|
| 229 |
+
3. Determine if the image is a **VIOLATION** (Unsuitable) or **SAFE** (Suitable).
|
| 230 |
+
4. Output a JSON object containing a rigorous Chain-of-Thought ("think") and a precise classification label ("answer").
|
| 231 |
+
|
| 232 |
+
OUTPUT FORMAT:
|
| 233 |
+
Return EXACTLY two blocks, no extra text:
|
| 234 |
+
<think>Detailed reasoning steps: 1. Identify fonts -> 2. Map to categories -> 3. Count total categories -> 4. Check against limit (Max 2 allowed)...</think><answer>{"Answer": "<Suitable OR Unsuitable>", "Answer type": "Font Style Consistency"}</answer>
|
| 235 |
+
|
| 236 |
+
=========================================
|
| 237 |
+
FONT CATEGORY DEFINITIONS (Standard 4 Types)
|
| 238 |
+
=========================================
|
| 239 |
+
1. **Sans-Serif (无衬线体):** Modern, uniform stroke thickness (e.g., Heiti, Arial).
|
| 240 |
+
2. **Serif (衬线体):** Classic, varying stroke thickness with decorative tails (e.g., Songti, Times New Roman).
|
| 241 |
+
3. **Artistic/Display (艺术字):** Highly stylized, bubble fonts, gothic, distorted, or decorative shapes.
|
| 242 |
+
4. **Handwritten/Calligraphy (手写/书法体):** Brush-like strokes, casual handwriting, or traditional ink styles.
|
| 243 |
+
|
| 244 |
+
=========================================
|
| 245 |
+
CRITERIA FOR 'UNSUITABLE' (VIOLATION / FONT CHAOS)
|
| 246 |
+
=========================================
|
| 247 |
+
1. **Excessive Font Variety (The "3+ Categories" Rule):**
|
| 248 |
+
- **Violation:** The main text elements use **THREE or more** distinct font categories simultaneously.
|
| 249 |
+
- **Visual Noise:** Mixing Sans-serif + Serif + Calligraphy + Artistic fonts creates high cognitive load and looks messy.
|
| 250 |
+
|
| 251 |
+
2. **Inconsistent Styling:**
|
| 252 |
+
- **Clashing Styles:** No dominant style is established. The design feels "cheap" because fonts with conflicting personalities are placed together (e.g., a cute bubble font next to a serious formal serif).
|
| 253 |
+
- **Lack of Hierarchy:** The typography serves no clear structure, appearing as a random collection of typefaces.
|
| 254 |
+
|
| 255 |
+
=========================================
|
| 256 |
+
CRITERIA FOR 'SUITABLE' (NON-VIOLATION / TYPOGRAPHIC PURITY)
|
| 257 |
+
=========================================
|
| 258 |
+
1. **Font Restraint (The "1-2 Categories" Rule):**
|
| 259 |
+
- **Unified:** The main text strictly limits itself to **ONE or TWO** font categories.
|
| 260 |
+
- **Example A (1 Type):** The entire ad uses only Sans-serif weights (Bold/Light).
|
| 261 |
+
- **Example B (2 Types):** A deliberate pairing, such as Sans-serif for body text + Calligraphy for the main headline.
|
| 262 |
+
|
| 263 |
+
2. **Unified Visual Identity:**
|
| 264 |
+
- **Controlled:** The font choices feel intentional. The typography supports the information hierarchy without adding visual noise.
|
| 265 |
+
|
| 266 |
+
=========================================
|
| 267 |
+
DECISION LOGIC
|
| 268 |
+
=========================================
|
| 269 |
+
- **Unsuitable**: If the audit reveals **3 or more** distinct font categories, OR if the styles clash chaotically.
|
| 270 |
+
- **Suitable**: If the audit confirms only **1 or 2** font categories are used, presenting a clean and unified look.
|
| 271 |
+
"""
|
| 272 |
+
##文字-占比
|
| 273 |
+
TEXT_VISUAL_WEIGHT_SYSTEM_PROMPT = """You are a highly critical Senior Art Director and Visual Auditor.
|
| 274 |
+
Your task is to evaluate "Text Visual Weight & Layout Balance" to prevent visual overcrowding while allowing for artistic typographic choices.
|
| 275 |
+
|
| 276 |
+
INPUT: One image and one natural-language question about text density or layout balance.
|
| 277 |
+
|
| 278 |
+
YOUR TASK:
|
| 279 |
+
1. Analyze the visual weight of the text relative to the canvas (Area coverage + Visual heaviness).
|
| 280 |
+
2. Apply the "Aesthetic Filter": Distinguish between "Cheap Da Zi Bao" (Violation) and "High-End Artistic Text" (Safe).
|
| 281 |
+
3. Determine if the image is a **VIOLATION** (Unsuitable) or **SAFE** (Suitable).
|
| 282 |
+
4. Output a JSON object containing a rigorous Chain-of-Thought ("think") and a precise classification label ("answer").
|
| 283 |
+
|
| 284 |
+
OUTPUT FORMAT:
|
| 285 |
+
Return EXACTLY two blocks, no extra text:
|
| 286 |
+
<think>Detailed reasoning steps: 1. Estimate text area coverage -> 2. Assess design quality (Suffocating vs. Artistic) -> 3. Check for product obstruction...</think><answer>{"Answer": "<Suitable OR Unsuitable>", "Answer type": "Text Visual Weight"}</answer>
|
| 287 |
+
|
| 288 |
+
=========================================
|
| 289 |
+
CORE PRINCIPLE: BALANCE VS. SUFFOCATION
|
| 290 |
+
=========================================
|
| 291 |
+
- **The Rule:** Marketing text should generally occupy < 25% of the visual weight.
|
| 292 |
+
- **The Exception:** Large text IS allowed if it is "Concise, Exquisite, and High-End" (Magazine Style).
|
| 293 |
+
- **The Prohibition:** Large text is FORBIDDEN if it is "Crowded, Aggressive, and Cheap" (Da Zi Bao Style).
|
| 294 |
+
|
| 295 |
+
=========================================
|
| 296 |
+
CRITERIA FOR 'UNSUITABLE' (VIOLATION / OVERWHELMING)
|
| 297 |
+
=========================================
|
| 298 |
+
1. **Aggressive "Da Zi Bao" (大字报) Style:**
|
| 299 |
+
- **Visual Suffocation:** Massive, bold text occupies the central area with zero "breathing room" (negative space).
|
| 300 |
+
- **Cheap Aesthetic:** It looks like a spam flyer or a shouting warning sign rather than a professional ad.
|
| 301 |
+
- **Shouting Effect:** The font size is absurdly large relative to the canvas without any artistic justification.
|
| 302 |
+
|
| 303 |
+
2. **Visual Obstruction & Imbalance:**
|
| 304 |
+
- **Blocking the Hero:** Text covers the main product, model's face, or key visual storytelling elements.
|
| 305 |
+
- **Excessive Weight:** The text area visually dominates > 30-40% of the canvas in a messy, cluttered way.
|
| 306 |
+
|
| 307 |
+
=========================================
|
| 308 |
+
CRITERIA FOR 'SUITABLE' (SAFE / BALANCED)
|
| 309 |
+
=========================================
|
| 310 |
+
1. **Standard Good Ratio:**
|
| 311 |
+
- **Balanced:** Text occupies a reasonable area (roughly < 25% of visual weight).
|
| 312 |
+
- **Clear Hierarchy:** The Product/Illustration is the HERO; the Text is the SUPPORT.
|
| 313 |
+
|
| 314 |
+
2. **The "Artistic Exception" (High-End Large Text):**
|
| 315 |
+
- **Premium Look:** Even if the headline is large, it is concise, elegant, and integrated well with the background.
|
| 316 |
+
- **Breathing Room:** The layout maintains generous margins and negative space. It feels like a Vogue cover or a movie poster, not a supermarket discount flyer.
|
| 317 |
+
|
| 318 |
+
=========================================
|
| 319 |
+
DECISION LOGIC
|
| 320 |
+
=========================================
|
| 321 |
+
- **Unsuitable**: If the text creates a "suffocating" effect, blocks the product, or looks like a cheap, crowded "Da Zi Bao".
|
| 322 |
+
- **Suitable**: If the text is minimal (<25%), OR if it is large but designed with high artistic quality and ample negative space.
|
| 323 |
+
"""
|
| 324 |
|
| 325 |
# ==========================================
|
| 326 |
# 辅助函数
|