import random from transformers import pipeline import re # Initialize the text generation pipeline try: generator = pipeline('text-generation', model='gpt2') except Exception as e: # Fallback for environments where Hugging Face models might not be available print("Warning: Using mock generator as fallback. Install transformers for full functionality.") class MockGenerator: def __call__(self, prompt, max_length=100, num_return_sequences=1): return [{"generated_text": prompt + " (This is a mock generation)"}] generator = MockGenerator() # Basic HTML templates def get_base_template(title, content, theme="light"): """Basic HTML template with proper structure and responsive meta tags""" css_theme = get_theme_css(theme) return f""" {title} {content} """ def get_theme_css(theme): """Generate CSS based on the selected theme""" themes = { "light": """ body { background-color: #ffffff; color: #333333; } a { color: #3b82f6; } .btn-primary { background-color: #3b82f6; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; transition: all 0.2s ease; } .btn-primary:hover { background-color: #2563eb; } .section { padding: 60px 0; } .hero { background-color: #f9fafb; } .card { background-color: #ffffff; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } """, "dark": """ body { background-color: #121212; color: #e0e0e0; } a { color: #90caf9; } .btn-primary { background-color: #90caf9; color: #121212; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; transition: all 0.2s ease; } .btn-primary:hover { background-color: #64b5f6; } .section { padding: 60px 0; } .hero { background-color: #1e1e1e; } .card { background-color: #1e1e1e; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); } """, "colorful": """ body { background-color: #ffffff; color: #333333; } a { color: #8b5cf6; } .btn-primary { background-color: #8b5cf6; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; transition: all 0.3s ease; } .btn-primary:hover { background-color: #7c3aed; transform: translateY(-2px); } .section { padding: 60px 0; } .hero { background: linear-gradient(135deg, #c084fc, #8b5cf6); color: white; } .card { background-color: #ffffff; border-radius: 8px; box-shadow: 0 10px 15px rgba(0,0,0,0.1); border-top: 4px solid #8b5cf6; transition: transform 0.3s ease; } .card:hover { transform: translateY(-5px); } .accent { color: #f472b6; } """ } return themes.get(theme.lower(), themes["light"]) # Website section templates def generate_navbar(site_name, pages=None): """Generate a navigation bar for the website""" if pages is None: pages = ["Home", "Features", "Pricing", "Contact"] links = "".join([f'{page}' for page in pages]) return f"""
""" def generate_hero_section(title, subtitle, cta="Get Started"): """Generate a hero section with a call to action""" return f"""

{title}

{subtitle}

{cta}
Hero Image Placeholder
""" def generate_features_section(features=None): """Generate a features section with cards""" if features is None: features = [ {"title": "Feature 1", "description": "Description of feature 1 and its benefits."}, {"title": "Feature 2", "description": "Description of feature 2 and its benefits."}, {"title": "Feature 3", "description": "Description of feature 3 and its benefits."} ] feature_cards = "" for feature in features: feature_cards += f"""

{feature['title']}

{feature['description']}

""" return f"""

Features

{feature_cards}
""" def generate_pricing_section(plans=None): """Generate a pricing section with different plans""" if plans is None: plans = [ { "name": "Basic", "price": "$9.99", "period": "month", "features": ["Feature 1", "Feature 2", "Email Support"], "highlighted": False }, { "name": "Pro", "price": "$19.99", "period": "month", "features": ["All Basic features", "Feature 3", "Feature 4", "Priority Support"], "highlighted": True }, { "name": "Enterprise", "price": "$49.99", "period": "month", "features": ["All Pro features", "Feature 5", "Feature 6", "24/7 Support", "Custom Integration"], "highlighted": False } ] pricing_cards = "" for plan in plans: highlight_style = "transform: scale(1.05);" if plan["highlighted"] else "" highlight_badge = '
Popular
' if plan["highlighted"] else "" features_list = "".join([f'
  • {feature}
  • ' for feature in plan["features"]]) pricing_cards += f"""
    {highlight_badge}

    {plan['name']}

    {plan['price']} /{plan['period']}
    Choose Plan
    """ return f"""

    Pricing

    Choose the perfect plan for your needs. All plans include our core features with different levels of support and additional functionalities.

    {pricing_cards}
    """ def generate_testimonials_section(testimonials=None): """Generate a testimonials section""" if testimonials is None: testimonials = [ {"name": "John Doe", "position": "CEO, Company A", "text": "This product has completely transformed how we operate our business. Highly recommended!"}, {"name": "Jane Smith", "position": "Marketing Director, Company B", "text": "The features and ease of use have made this an essential tool in our daily operations."}, {"name": "Mike Johnson", "position": "Freelancer", "text": "As someone who works independently, this tool has saved me countless hours of work."} ] testimonial_cards = "" for testimonial in testimonials: testimonial_cards += f"""
    "

    {testimonial['text']}

    {testimonial['name']}
    {testimonial['position']}
    """ return f"""

    What Our Customers Say

    {testimonial_cards}
    """ def generate_contact_section(): """Generate a contact section with a form""" return f"""

    Contact Us

    """ def generate_website_html(title, sections): """ Generate the complete HTML for a website. :param title: The title of the website. :param sections: A list of HTML sections to include in the body. :return: A complete HTML string. """ content = "".join(sections) return get_base_template(title, content, theme="light")