File size: 886 Bytes
f3bc981
d475e29
 
09f8d76
5edc6a5
09f8d76
 
c886a44
5edc6a5
c886a44
727e43b
 
c886a44
 
 
 
 
5edc6a5
09f8d76
727e43b
09f8d76
c886a44
 
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
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"{name}.html"  # Return the file path directly
    except Exception as e:
        return None  # Returning None for the Gradio interface to handle errors gracefully

def generate_and_download(name, code):
    file_path = generate_html(name, code)
    if file_path and os.path.exists(file_path):
        return file_path  # Return the path for download
    else:
        return None  # Handle if the file couldn't be created

demo = gr.Interface(
    fn=generate_and_download,
    inputs=[
        gr.Textbox(label="File Name", placeholder="Enter file name without extension"),
        gr.Code(label="HTML Code", language="html")
    ],
    outputs=gr.File(label="Download HTML File"),
    title="HTML Generator"
)

demo.launch()