Spaces:
Running
Running
import gradio as gr | |
import os | |
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: | |
return f.read() | |
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() |