Spaces:
Sleeping
Sleeping
File size: 24,831 Bytes
0db40c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | """
Test script for specific problematic SVG cases
Tests the following cases that were reported to have issues:
1. tourism_cities_3_financial_centers.svg
2. tech_companies_1_rounded_label_big_title.svg
3. renewable_power_3_inline_contrast_triple.svg
4. life_expectancy_2_comic_bouncy_emphasis.svg
5. life_expectancy_1_stacked_badge_headline.svg
6. europe_cars_2_comic_bouncy_emphasis.svg
7. education_cost_1_comic_bold_announcement.svg
8. arctic_ice_decline_1_highlight_stripe.svg
"""
from modules.title_styler.infographic_title_generator import generate_title
# Problematic cases with their corresponding test data and templates
# Each case includes manually segmented title text to match template segments
PROBLEMATIC_CASES = [
{
"test_id": "tourism_cities",
# financial_centers: 3 segments (black + primary bg + black)
"title_segments": "Top 10 Most\nVisited Cities\nin 2024",
"description": "Annual tourism statistics reveal which urban destinations attracted the most international visitors last year",
"primary_color": "#E67E22",
"background_color": "#FFFFFF",
"template_name": "financial_centers",
"output_file": "tourism_cities_3_financial_centers.svg"
},
{
"test_id": "tech_companies",
# rounded_label_big_title: 2 segments (label badge + headline)
"title_segments": "TECH\nAmerica's Largest Technology Companies",
"description": "Market capitalization comparison of leading tech firms headquartered in the United States",
"primary_color": "#8E44AD",
"background_color": "#F5F5F5",
"template_name": "rounded_label_big_title",
"output_file": "tech_companies_1_rounded_label_big_title.svg"
},
{
"test_id": "renewable_power",
# inline_contrast_triple: 3 inline segments
"title_segments": "Renewable Energy\nShare\nof Total Electricity Generation",
"description": "Tracking the percentage of power generated from solar, wind, hydro, and other renewable sources by country",
"primary_color": "#16A085",
"background_color": "#ECF0F1",
"template_name": "inline_contrast_triple",
"output_file": "renewable_power_3_inline_contrast_triple.svg"
},
{
"test_id": "life_expectancy",
# comic_bouncy_emphasis: 3 inline segments
"title_segments": "Average\nLife Expectancy\nGains Since 1950",
"description": "How longevity has improved across different regions over seven decades of global development",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "comic_bouncy_emphasis",
"output_file": "life_expectancy_2_comic_bouncy_emphasis.svg"
},
{
"test_id": "life_expectancy",
# stacked_badge_headline: 3 segments (badge + headline + tagline)
"title_segments": "LONGEVITY\nLife Expectancy Gains\nSince 1950",
"description": "How longevity has improved across different regions over seven decades of global development",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "stacked_badge_headline",
"output_file": "life_expectancy_1_stacked_badge_headline.svg"
},
{
"test_id": "europe_cars",
# comic_bouncy_emphasis: 3 inline segments
"title_segments": "Europe's\nBest-Selling\nCar Brands in H1 2025",
"description": "This visualization shows the best-selling car brands in Europe",
"primary_color": "#1E5BBD",
"background_color": "#E8E8E8",
"template_name": "comic_bouncy_emphasis",
"output_file": "europe_cars_2_comic_bouncy_emphasis.svg"
},
{
"test_id": "education_cost",
# comic_bold_announcement: 1 segment (single huge title)
"title_segments": "The Rising Cost of Higher Education",
"description": "How tuition fees have increased across different types of universities over the past two decades",
"primary_color": "#C0392B",
"background_color": "#F9F9F9",
"template_name": "comic_bold_announcement",
"output_file": "education_cost_1_comic_bold_announcement.svg"
},
{
"test_id": "arctic_ice_decline",
# highlight_stripe: 2 segments (lead-in + highlighted core)
"title_segments": "The Dramatic Decline of\nArctic Sea Ice Coverage Over the Past Four Decades",
"description": "Satellite imagery and climate data reveal unprecedented melting patterns affecting polar ecosystems and global weather",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "highlight_stripe",
"output_file": "arctic_ice_decline_1_highlight_stripe.svg"
}
]
# Comprehensive test cases for all 48 templates
FULL_TEMPLATE_TEST_CASES = [
{
"test_id": "three_line_emphasis",
"title_segments": "Average\nLife Expectancy\nGains Since 1950",
"description": "How longevity has improved across different regions over seven decades",
"primary_color": "#E67E22",
"background_color": "#FFFFFF",
"template_name": "three_line_emphasis",
"output_file": "three_line_emphasis_test.svg"
},
{
"test_id": "two_line_hierarchy",
"title_segments": "The Evolution of\nArtificial Intelligence",
"description": "From early neural networks to modern large language models",
"primary_color": "#F5F5F5",
"background_color": "#8E44AD",
"template_name": "two_line_hierarchy",
"output_file": "two_line_hierarchy_test.svg"
},
{
"test_id": "lithium_countries",
"title_segments": "World's Largest\nLithium Producers",
"description": "Countries leading the global lithium extraction industry",
"primary_color": "#16A085",
"background_color": "#ECF0F1",
"template_name": "lithium_countries",
"output_file": "lithium_countries_test.svg"
},
{
"test_id": "european_adults",
"title_segments": "Among European Adults\nSmoking Rates Decline",
"description": "Public health campaigns and regulations drive behavioral change",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "european_adults",
"output_file": "european_adults_test.svg"
},
{
"test_id": "millionaires_green",
"title_segments": "Number of\nMillionaires by Country",
"description": "Wealth distribution across major economies worldwide",
"primary_color": "#1E5BBD",
"background_color": "#E8E8E8",
"template_name": "millionaires_green",
"output_file": "millionaires_green_test.svg"
},
{
"test_id": "america_valuable",
"title_segments": "America's\nMost Valuable\nTech\nCompanies",
"description": "Market capitalization of leading technology firms",
"primary_color": "#C0392B",
"background_color": "#F9F9F9",
"template_name": "america_valuable",
"output_file": "america_valuable_test.svg"
},
{
"test_id": "dentist_question",
"title_segments": "How Many People\nVisit the Dentist Annually?",
"description": "Dental care access and frequency across different demographics",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "dentist_question",
"output_file": "dentist_question_test.svg"
},
{
"test_id": "infant_mortality",
"title_segments": "HEALTH\nInfant Mortality Rates by Region",
"description": "Global health indicators tracking child survival rates",
"primary_color": "#FF00FF",
"background_color": "#333333",
"template_name": "infant_mortality",
"output_file": "infant_mortality_test.svg"
},
{
"test_id": "financial_centers",
"title_segments": "Top 10\nGlobal Financial Centers\nRanked by GDP",
"description": "Economic powerhouses driving international finance",
"primary_color": "#E74C3C",
"background_color": "#F0F0F0",
"template_name": "financial_centers",
"output_file": "financial_centers_test.svg"
},
{
"test_id": "innovative_countries",
"title_segments": "Innovation Index\nMost Innovative Countries\nand Their Scores",
"description": "R&D investment and patent output rankings",
"primary_color": "#3498DB",
"background_color": "#FFFFFF",
"template_name": "innovative_countries",
"output_file": "innovative_countries_test.svg"
},
{
"test_id": "americas_wealth",
"title_segments": "Total Household Wealth in North America",
"description": "Combined assets of families across the United States and Canada",
"primary_color": "#E67E22",
"background_color": "#2C3E50",
"template_name": "americas_wealth",
"output_file": "americas_wealth_test.svg"
},
{
"test_id": "china_dominance",
"title_segments": "China's\nGrowing\nEconomic Influence",
"description": "Trade relationships and investment patterns worldwide",
"primary_color": "#16A085",
"background_color": "#ECF0F1",
"template_name": "china_dominance",
"output_file": "china_dominance_test.svg"
},
{
"test_id": "magazine_cover",
"title_segments": "FEATURE STORY\nThe Future of Space Exploration\nNew Frontiers Ahead",
"description": "Innovations in rocket technology and planetary missions",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "magazine_cover",
"output_file": "magazine_cover_test.svg"
},
{
"test_id": "newspaper_headline",
"title_segments": "Climate Agreement Reached at International Summit",
"description": "World leaders commit to ambitious carbon reduction targets",
"primary_color": "#1E5BBD",
"background_color": "#E8E8E8",
"template_name": "newspaper_headline",
"output_file": "newspaper_headline_test.svg"
},
{
"test_id": "elegant_serif",
"title_segments": "The Philosophy of\nSustainable Development",
"description": "Balancing economic growth with environmental preservation",
"primary_color": "#C0392B",
"background_color": "#F9F9F9",
"template_name": "elegant_serif",
"output_file": "elegant_serif_test.svg"
},
{
"test_id": "data_report",
"title_segments": "Q3 2024\n+18% Revenue Growth",
"description": "Quarterly financial performance exceeds analyst expectations",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "data_report",
"output_file": "data_report_test.svg"
},
{
"test_id": "corporate_brand",
"title_segments": "INNOVATION THROUGH COLLABORATION",
"description": "Our commitment to advancing technology for everyone",
"primary_color": "#27AE60",
"background_color": "#FAFAFA",
"template_name": "corporate_brand",
"output_file": "corporate_brand_test.svg"
},
{
"test_id": "corporate_brand_desc_gap",
"title_segments": "Full-Day Kindergarten Outperforms Half-Day on Reading Scores",
"description": "ReadingScores for Half-Day and Full-Day kindergarten students (from 2015 to 2023) consistently indicate higher performance in Full-Day.",
"primary_color": "#f8dd3d",
"background_color": "#E2F1F6",
"template_name": "corporate_brand",
"output_file": "corporate_brand_desc_gap_test.svg"
},
{
"test_id": "academic_paper",
"title_segments": "Machine Learning Applications\nin Climate Science",
"description": "Improving weather prediction models with AI techniques",
"primary_color": "#E74C3C",
"background_color": "#F0F0F0",
"template_name": "academic_paper",
"output_file": "academic_paper_test.svg"
},
{
"test_id": "tech_startup",
"title_segments": "Move Fast\nBreak Barriers",
"description": "Our mission to disrupt traditional industries",
"primary_color": "#3498DB",
"background_color": "#FFFFFF",
"template_name": "tech_startup",
"output_file": "tech_startup_test.svg"
},
{
"test_id": "poster_impact",
"title_segments": "JOIN THE REVOLUTION\nTogether We Rise",
"description": "Community-driven social change movement",
"primary_color": "#E67E22",
"background_color": "#FFFFFF",
"template_name": "poster_impact",
"output_file": "poster_impact_test.svg"
},
{
"test_id": "vintage_style",
"title_segments": "Est. 1887\nHeritage Coffee Co.\nAuthentic Roasters",
"description": "Traditional craftsmanship meets modern taste",
"primary_color": "#8E44AD",
"background_color": "#F5F5F5",
"template_name": "vintage_style",
"output_file": "vintage_style_test.svg"
},
{
"test_id": "europe_brands",
"title_segments": "EUROPE\nBest-Selling Car Brands in 2024",
"description": "Consumer preferences across major European markets",
"primary_color": "#16A085",
"background_color": "#ECF0F1",
"template_name": "europe_brands",
"output_file": "europe_brands_test.svg"
},
{
"test_id": "international_students",
"title_segments": "Asia's\nTop Universities\nfor International Students",
"description": "Rankings based on diversity and academic excellence",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "international_students",
"output_file": "international_students_test.svg"
},
{
"test_id": "kpi_number_pill",
"title_segments": "QUARTERLY REVENUE\n$2.4 Billion",
"description": "Record-breaking sales driven by product innovation",
"primary_color": "#1E5BBD",
"background_color": "#E8E8E8",
"template_name": "kpi_number_pill",
"output_file": "kpi_number_pill_test.svg"
},
{
"test_id": "timeline_year_span",
"title_segments": "Looking Back at\n1990-2020\nTechnology Evolution",
"description": "Three decades of digital transformation",
"primary_color": "#C0392B",
"background_color": "#F9F9F9",
"template_name": "timeline_year_span",
"output_file": "timeline_year_span_test.svg"
},
{
"test_id": "stacked_badge_headline",
"title_segments": "SUSTAINABILITY\nCarbon Emissions Reduction\nSince 2010",
"description": "Progress toward net-zero goals across industries",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "stacked_badge_headline",
"output_file": "stacked_badge_headline_test.svg"
},
{
"test_id": "right_align_elegant_duo",
"title_segments": "Across Major Cities\nUrban Population Density",
"description": "Comparing metropolitan areas worldwide",
"primary_color": "#27AE60",
"background_color": "#FAFAFA",
"template_name": "right_align_elegant_duo",
"output_file": "right_align_elegant_duo_test.svg"
},
{
"test_id": "inline_contrast_triple",
"title_segments": "The Rise of\nElectric Vehicles\nin Global Markets",
"description": "Adoption rates accelerate with policy support",
"primary_color": "#E74C3C",
"background_color": "#F0F0F0",
"template_name": "inline_contrast_triple",
"output_file": "inline_contrast_triple_test.svg"
},
{
"test_id": "split_colon_emphasis",
"title_segments": "INNOVATION REPORT:\nBreakthrough Technologies of 2024",
"description": "Scientific advances transforming daily life",
"primary_color": "#3498DB",
"background_color": "#FFFFFF",
"template_name": "split_colon_emphasis",
"output_file": "split_colon_emphasis_test.svg"
},
{
"test_id": "minimal_right_caption",
"title_segments": "Global Trade Volumes",
"description": "International commerce statistics",
"primary_color": "#E67E22",
"background_color": "#FFFFFF",
"template_name": "minimal_right_caption",
"output_file": "minimal_right_caption_test.svg"
},
{
"test_id": "two_tone_upper",
"title_segments": "MARKET ANALYSIS\nCRYPTOCURRENCY TRENDS",
"description": "Digital asset valuations and regulatory developments",
"primary_color": "#8E44AD",
"background_color": "#F5F5F5",
"template_name": "two_tone_upper",
"output_file": "two_tone_upper_test.svg"
},
{
"test_id": "rounded_label_big_title",
"title_segments": "TECH\nArtificial Intelligence Market Growth",
"description": "Industry valuation surpasses $500 billion",
"primary_color": "#16A085",
"background_color": "#ECF0F1",
"template_name": "rounded_label_big_title",
"output_file": "rounded_label_big_title_test.svg"
},
{
"test_id": "underlined_statement",
"title_segments": "The Future Belongs to Renewable Energy",
"description": "Sustainable power generation becomes economically dominant",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "underlined_statement",
"output_file": "underlined_statement_test.svg"
},
{
"test_id": "soft_shadow_duo",
"title_segments": "Throughout History\nRevolutionary Inventions",
"description": "Innovations that changed human civilization",
"primary_color": "#1E5BBD",
"background_color": "#E8E8E8",
"template_name": "soft_shadow_duo",
"output_file": "soft_shadow_duo_test.svg"
},
{
"test_id": "comic_fun_title",
"title_segments": "Super Amazing Facts About Space!",
"description": "Mind-blowing discoveries about our universe",
"primary_color": "#C0392B",
"background_color": "#F9F9F9",
"template_name": "comic_fun_title",
"output_file": "comic_fun_title_test.svg"
},
{
"test_id": "comic_bubble_speech",
"title_segments": "Guess What?\nPandas Eat 40kg Bamboo Daily!",
"description": "Incredible animal eating habits revealed",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "comic_bubble_speech",
"output_file": "comic_bubble_speech_test.svg"
},
{
"test_id": "comic_bouncy_emphasis",
"title_segments": "World's\nCoolest\nGadgets of 2024",
"description": "The most exciting tech toys released this year",
"primary_color": "#E74C3C",
"background_color": "#F0F0F0",
"template_name": "comic_bouncy_emphasis",
"output_file": "comic_bouncy_emphasis_test.svg"
},
{
"test_id": "comic_playful_label",
"title_segments": "FUN FACTS\nOceans Cover 71% of Earth!",
"description": "Amazing things you never knew about our planet",
"primary_color": "#3498DB",
"background_color": "#FFFFFF",
"template_name": "comic_playful_label",
"output_file": "comic_playful_label_test.svg"
},
{
"test_id": "comic_question_fun",
"title_segments": "Did You Know?\nBananas Are Berries!",
"description": "Surprising botanical classification facts",
"primary_color": "#E67E22",
"background_color": "#FFFFFF",
"template_name": "comic_question_fun",
"output_file": "comic_question_fun_test.svg"
},
{
"test_id": "comic_bold_announcement",
"title_segments": "The Most Incredible Animal Superpowers!",
"description": "Nature's amazing adaptations and abilities",
"primary_color": "#8E44AD",
"background_color": "#F5F5F5",
"template_name": "comic_bold_announcement",
"output_file": "comic_bold_announcement_test.svg"
},
{
"test_id": "comic_wavy_text",
"title_segments": "Get Ready for\nAdventure Time!",
"description": "Exciting outdoor activities for families",
"primary_color": "#9B59B6",
"background_color": "#FFFFFF",
"template_name": "comic_wavy_text",
"output_file": "comic_wavy_text_test.svg"
},
{
"test_id": "comic_mega_title",
"title_segments": "Ultimate Gaming Champions Tournament!",
"description": "Epic esports competition draws global audience",
"primary_color": "#2C3E50",
"background_color": "#FFFFFF",
"template_name": "comic_mega_title",
"output_file": "comic_mega_title_test.svg"
},
{
"test_id": "comic_sticker_style",
"title_segments": "AWESOME\nSpace Mission Success!",
"description": "Satellite deployment achieves perfect orbit",
"primary_color": "#27AE60",
"background_color": "#FAFAFA",
"template_name": "comic_sticker_style",
"output_file": "comic_sticker_style_test.svg"
},
]
def test_single_case(test_case):
"""
Test a single problematic case
Args:
test_case: Dictionary containing title_segments, description, colors, template_name, etc.
Returns:
Result of the generation
"""
print("\n" + "=" * 70)
print(f"Testing: {test_case['output_file']}")
print("=" * 70)
print(f"Title segments: {test_case['title_segments']}")
if len(test_case['description']) > 60:
print(f"Description: {test_case['description'][:60]}...")
else:
print(f"Description: {test_case['description']}")
print(f"Template: {test_case['template_name']}")
print(f"Primary Color: {test_case['primary_color']}")
print(f"Background Color: {test_case['background_color']}")
print("=" * 70)
try:
results = generate_title(
title=test_case['title_segments'], # Pass list of segments
description=test_case['description'],
primary_color=test_case['primary_color'],
background_color=test_case['background_color'],
template_name=test_case['template_name'],
max_width=900,
use_llm=False, # Use specified template directly
save_to=f"output/{test_case['test_id']}"
)
if results:
result = results[0]
print(f"β
Successfully generated:")
print(f" Template: {result['template_name']}")
print(f" Size: {result['width']:.0f}px Γ {result['height']:.0f}px")
print(f" Saved as: output/{test_case['output_file']}")
return True
else:
print(f"β Failed to generate")
return False
except Exception as e:
print(f"β Error: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
import sys
# Determine which test suite to run
if len(sys.argv) > 1 and sys.argv[1] == '--all':
test_suite = FULL_TEMPLATE_TEST_CASES
suite_name = "ALL TEMPLATES"
elif len(sys.argv) > 1 and sys.argv[1] == '--problematic':
test_suite = PROBLEMATIC_CASES
suite_name = "PROBLEMATIC CASES"
else:
# Default: run full template tests
test_suite = FULL_TEMPLATE_TEST_CASES
suite_name = "ALL TEMPLATES (DEFAULT)"
print("π‘ Tip: Use '--problematic' to run only problematic cases")
print("π‘ Tip: Use '--all' to explicitly run all template tests")
print()
print("=" * 70)
print(f"TESTING {suite_name}")
print(f"Total cases to test: {len(test_suite)}")
print("=" * 70)
success_count = 0
failed_count = 0
for i, test_case in enumerate(test_suite, 1):
print(f"\n[{i}/{len(test_suite)}]")
if test_single_case(test_case):
success_count += 1
else:
failed_count += 1
print(f"Failed: {test_case['output_file']}")
# Summary
print("\n" + "=" * 70)
print("TEST SUMMARY")
print("=" * 70)
print(f"Total test cases: {len(test_suite)}")
print(f"β
Successful: {success_count}")
print(f"β Failed: {failed_count}")
print("=" * 70)
if failed_count > 0:
print("\nβ οΈ Some tests failed. Please review the errors above.")
else:
print("\nβ
All tests passed!")
print("=" * 70)
|