Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,26 +5,22 @@ def generate_html(name, code):
|
|
5 |
try:
|
6 |
with open(f"{name}.html", "w") as f:
|
7 |
f.write(code)
|
8 |
-
return f"
|
9 |
except Exception as e:
|
10 |
-
return
|
11 |
-
|
12 |
-
def download_file(name):
|
13 |
-
try:
|
14 |
-
with open(f"{name}.html", "rb") as f:
|
15 |
-
return f.read()
|
16 |
-
except Exception as e:
|
17 |
-
return None
|
18 |
|
19 |
def generate_and_download(name, code):
|
20 |
-
generate_html(name, code)
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
demo = gr.Interface(
|
24 |
fn=generate_and_download,
|
25 |
inputs=[
|
26 |
-
gr.Textbox(label="File Name"),
|
27 |
-
gr.Code(label="HTML Code")
|
28 |
],
|
29 |
outputs=gr.File(label="Download HTML File"),
|
30 |
title="HTML Generator"
|
|
|
5 |
try:
|
6 |
with open(f"{name}.html", "w") as f:
|
7 |
f.write(code)
|
8 |
+
return f"{name}.html" # Return the file path directly
|
9 |
except Exception as e:
|
10 |
+
return None # Returning None for the Gradio interface to handle errors gracefully
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def generate_and_download(name, code):
|
13 |
+
file_path = generate_html(name, code)
|
14 |
+
if file_path and os.path.exists(file_path):
|
15 |
+
return file_path # Return the path for download
|
16 |
+
else:
|
17 |
+
return None # Handle if the file couldn't be created
|
18 |
|
19 |
demo = gr.Interface(
|
20 |
fn=generate_and_download,
|
21 |
inputs=[
|
22 |
+
gr.Textbox(label="File Name", placeholder="Enter file name without extension"),
|
23 |
+
gr.Code(label="HTML Code", language="html")
|
24 |
],
|
25 |
outputs=gr.File(label="Download HTML File"),
|
26 |
title="HTML Generator"
|