ElonMuskTeslaMarketingDepartment commited on
Commit
06a4b95
·
verified ·
1 Parent(s): 5b67956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from io import StringIO
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 (note: links like "Touchless delivery" are kept as-is; edit manually if needed)
232
  html = HTML_TEMPLATE.format(
233
  title_one=title_one,
234
- subtitle_one=subtitle_one.replace("order online for <a href='signup.html'>Touchless delivery</a>", "order online for <a href='signup.html'>Touchless delivery</a>"), # Preserve HTML
235
  btn_primary_one=btn_primary_one,
236
  btn_secondary_one=btn_secondary_one,
237
  title_two=title_two,
238
- subtitle_two=subtitle_two.replace("order online for <a href='signup.html'>Touchless delivery</a>", "order online for <a href='signup.html'>Touchless delivery</a>"),
239
  btn_primary_two=btn_primary_two,
240
  btn_secondary_two=btn_secondary_two,
241
  title_three=title_three,
242
- subtitle_three=subtitle_three.replace("order online for <a href='signup.html'>Touchless delivery</a>", "order online for <a href='signup.html'>Touchless delivery</a>"),
243
  btn_primary_three=btn_primary_three,
244
  btn_secondary_three=btn_secondary_three,
245
  title_four=title_four,
246
- subtitle_four=subtitle_four.replace("order online for <a href='signup.html'>Touchless delivery</a>", "order online for <a href='signup.html'>Touchless delivery</a>"),
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
- return html, html # Return for preview and download
 
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", visible=False)
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__":