Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from io import
|
| 3 |
import base64
|
| 4 |
|
| 5 |
# HTML template with placeholders like {title_one}, {subtitle_one}, etc.
|
|
@@ -228,22 +228,22 @@ def generate_html(
|
|
| 228 |
title_six, subtitle_six, btn_primary_six, btn_secondary_six,
|
| 229 |
title_seven, btn_primary_seven
|
| 230 |
):
|
| 231 |
-
# Inject values into template
|
| 232 |
html = HTML_TEMPLATE.format(
|
| 233 |
title_one=title_one,
|
| 234 |
-
subtitle_one=subtitle_one
|
| 235 |
btn_primary_one=btn_primary_one,
|
| 236 |
btn_secondary_one=btn_secondary_one,
|
| 237 |
title_two=title_two,
|
| 238 |
-
subtitle_two=subtitle_two
|
| 239 |
btn_primary_two=btn_primary_two,
|
| 240 |
btn_secondary_two=btn_secondary_two,
|
| 241 |
title_three=title_three,
|
| 242 |
-
subtitle_three=subtitle_three
|
| 243 |
btn_primary_three=btn_primary_three,
|
| 244 |
btn_secondary_three=btn_secondary_three,
|
| 245 |
title_four=title_four,
|
| 246 |
-
subtitle_four=subtitle_four
|
| 247 |
btn_primary_four=btn_primary_four,
|
| 248 |
btn_secondary_four=btn_secondary_four,
|
| 249 |
title_five=title_five,
|
|
@@ -257,7 +257,8 @@ def generate_html(
|
|
| 257 |
title_seven=title_seven,
|
| 258 |
btn_primary_seven=btn_primary_seven
|
| 259 |
)
|
| 260 |
-
|
|
|
|
| 261 |
|
| 262 |
with gr.Blocks(title="Tesla Page Editor") as demo:
|
| 263 |
gr.Markdown("# Tesla Page Text Editor\nEdit texts below to customize sections for visitor engagement. Preview scrolls like the original!")
|
|
@@ -308,7 +309,7 @@ with gr.Blocks(title="Tesla Page Editor") as demo:
|
|
| 308 |
|
| 309 |
with gr.Column(scale=2):
|
| 310 |
preview = gr.HTML(label="Live Preview")
|
| 311 |
-
download = gr.File(label="Download Updated index.html",
|
| 312 |
|
| 313 |
generate_btn.click(
|
| 314 |
generate_html,
|
|
@@ -322,8 +323,6 @@ with gr.Blocks(title="Tesla Page Editor") as demo:
|
|
| 322 |
title_seven, btn_primary_seven
|
| 323 |
],
|
| 324 |
outputs=[download, preview]
|
| 325 |
-
).then(
|
| 326 |
-
lambda: gr.update(visible=True), outputs=[download]
|
| 327 |
)
|
| 328 |
|
| 329 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from io import BytesIO
|
| 3 |
import base64
|
| 4 |
|
| 5 |
# HTML template with placeholders like {title_one}, {subtitle_one}, etc.
|
|
|
|
| 228 |
title_six, subtitle_six, btn_primary_six, btn_secondary_six,
|
| 229 |
title_seven, btn_primary_seven
|
| 230 |
):
|
| 231 |
+
# Inject values into template
|
| 232 |
html = HTML_TEMPLATE.format(
|
| 233 |
title_one=title_one,
|
| 234 |
+
subtitle_one=subtitle_one,
|
| 235 |
btn_primary_one=btn_primary_one,
|
| 236 |
btn_secondary_one=btn_secondary_one,
|
| 237 |
title_two=title_two,
|
| 238 |
+
subtitle_two=subtitle_two,
|
| 239 |
btn_primary_two=btn_primary_two,
|
| 240 |
btn_secondary_two=btn_secondary_two,
|
| 241 |
title_three=title_three,
|
| 242 |
+
subtitle_three=subtitle_three,
|
| 243 |
btn_primary_three=btn_primary_three,
|
| 244 |
btn_secondary_three=btn_secondary_three,
|
| 245 |
title_four=title_four,
|
| 246 |
+
subtitle_four=subtitle_four,
|
| 247 |
btn_primary_four=btn_primary_four,
|
| 248 |
btn_secondary_four=btn_secondary_four,
|
| 249 |
title_five=title_five,
|
|
|
|
| 257 |
title_seven=title_seven,
|
| 258 |
btn_primary_seven=btn_primary_seven
|
| 259 |
)
|
| 260 |
+
# Return as bytes for File component
|
| 261 |
+
return html.encode('utf-8'), html
|
| 262 |
|
| 263 |
with gr.Blocks(title="Tesla Page Editor") as demo:
|
| 264 |
gr.Markdown("# Tesla Page Text Editor\nEdit texts below to customize sections for visitor engagement. Preview scrolls like the original!")
|
|
|
|
| 309 |
|
| 310 |
with gr.Column(scale=2):
|
| 311 |
preview = gr.HTML(label="Live Preview")
|
| 312 |
+
download = gr.File(label="Download Updated index.html", file_types=[".html"])
|
| 313 |
|
| 314 |
generate_btn.click(
|
| 315 |
generate_html,
|
|
|
|
| 323 |
title_seven, btn_primary_seven
|
| 324 |
],
|
| 325 |
outputs=[download, preview]
|
|
|
|
|
|
|
| 326 |
)
|
| 327 |
|
| 328 |
if __name__ == "__main__":
|