Spaces:
Running
Running
File size: 941 Bytes
f3bc981 d475e29 4ce8d70 d475e29 09f8d76 5edc6a5 09f8d76 727e43b 5edc6a5 727e43b 5edc6a5 09f8d76 727e43b 09f8d76 727e43b 09f8d76 5edc6a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
import os
import base64
def generate_html(name, code):
try:
with open(f"{name}.html", "w") as f:
f.write(code)
return f"HTML file {name}.html generated successfully!"
except Exception as e:
return f"Error generating HTML file: {str(e)}"
def download_file(name):
try:
with open(f"{name}.html", "rb") as f:
bytes_data = f.read()
encoded_data = base64.b64encode(bytes_data).decode("utf-8")
return {"name": f"{name}.html", "data": encoded_data}
except Exception as e:
return None
def generate_and_download(name, code):
generate_html(name, code)
return download_file(name)
demo = gr.Interface(
fn=generate_and_download,
inputs=[
gr.Textbox(label="File Name"),
gr.Code(label="HTML Code")
],
outputs=gr.File(label="Download HTML File"),
title="HTML Generator"
)
demo.launch() |