import gradio as gr
import tempfile
# HTML template with placeholders like {title_one}, {subtitle_one}, etc.
HTML_TEMPLATE = """
{title_one}
{subtitle_one}
{title_two}
{subtitle_two}
{title_three}
{subtitle_three}
{title_four}
{subtitle_four}
{title_five}
{subtitle_five}
{title_six}
{subtitle_six}
"""
def generate_html(
title_one, subtitle_one, btn_primary_one, btn_secondary_one,
title_two, subtitle_two, btn_primary_two, btn_secondary_two,
title_three, subtitle_three, btn_primary_three, btn_secondary_three,
title_four, subtitle_four, btn_primary_four, btn_secondary_four,
title_five, subtitle_five, btn_primary_five, btn_secondary_five,
title_six, subtitle_six, btn_primary_six, btn_secondary_six,
title_seven, btn_primary_seven
):
# Inject values into template
html = HTML_TEMPLATE.format(
title_one=title_one,
subtitle_one=subtitle_one,
btn_primary_one=btn_primary_one,
btn_secondary_one=btn_secondary_one,
title_two=title_two,
subtitle_two=subtitle_two,
btn_primary_two=btn_primary_two,
btn_secondary_two=btn_secondary_two,
title_three=title_three,
subtitle_three=subtitle_three,
btn_primary_three=btn_primary_three,
btn_secondary_three=btn_secondary_three,
title_four=title_four,
subtitle_four=subtitle_four,
btn_primary_four=btn_primary_four,
btn_secondary_four=btn_secondary_four,
title_five=title_five,
subtitle_five=subtitle_five,
btn_primary_five=btn_primary_five,
btn_secondary_five=btn_secondary_five,
title_six=title_six,
subtitle_six=subtitle_six,
btn_primary_six=btn_primary_six,
btn_secondary_six=btn_secondary_six,
title_seven=title_seven,
btn_primary_seven=btn_primary_seven
)
# Create a temporary file for the HTML
with tempfile.NamedTemporaryFile(mode='w+', suffix='.html', delete=False, encoding='utf-8') as tmp_file:
tmp_file.write(html)
tmp_path = tmp_file.name
return tmp_path, html
with gr.Blocks(title="Tesla Page Editor") as demo:
gr.Markdown("# Tesla Page Text Editor\nEdit texts below to customize sections for visitor engagement. Preview scrolls like the original!")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Section 1 (Model S)")
title_one = gr.Textbox("Model S", label="Title")
subtitle_one = gr.Textbox("order online for