Ray1ee01's picture
Upload folder using huggingface_hub
0db40c8 verified
Raw
History Blame Contribute Delete
24.8 kB
"""
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)