Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
|
|
|
| 3 |
|
| 4 |
def save_webpage(url, save_method, javascript):
|
| 5 |
# Command to execute
|
|
@@ -20,12 +21,20 @@ def save_webpage(url, save_method, javascript):
|
|
| 20 |
command_str = " ".join(command) + f" > {output_file}"
|
| 21 |
|
| 22 |
# Execute the command
|
| 23 |
-
subprocess.run(command_str, shell=True)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Gradio Interface
|
| 31 |
iface = gr.Interface(
|
|
@@ -35,7 +44,11 @@ iface = gr.Interface(
|
|
| 35 |
gr.Radio(choices=["From URL", "From Saved File"], label="Save Method"),
|
| 36 |
gr.Checkbox(label="Enable JavaScript"),
|
| 37 |
],
|
| 38 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
title="Webpage to HTML Converter",
|
| 40 |
description="Convert a webpage to a single HTML file for offline use."
|
| 41 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
def save_webpage(url, save_method, javascript):
|
| 6 |
# Command to execute
|
|
|
|
| 21 |
command_str = " ".join(command) + f" > {output_file}"
|
| 22 |
|
| 23 |
# Execute the command
|
| 24 |
+
result = subprocess.run(command_str, shell=True, capture_output=True, text=True)
|
| 25 |
|
| 26 |
+
# Check for warnings
|
| 27 |
+
warning_message = ""
|
| 28 |
+
if "[ WARN ]" in result.stderr:
|
| 29 |
+
warning_message = result.stderr.split("[ WARN ]")[1].strip()
|
| 30 |
|
| 31 |
+
# Read the output HTML file
|
| 32 |
+
if os.path.exists(output_file):
|
| 33 |
+
with open(output_file, "r", encoding="utf-8") as file:
|
| 34 |
+
html_content = file.read()
|
| 35 |
+
return html_content, warning_message, output_file
|
| 36 |
+
else:
|
| 37 |
+
return "", "Error: HTML file not created", ""
|
| 38 |
|
| 39 |
# Gradio Interface
|
| 40 |
iface = gr.Interface(
|
|
|
|
| 44 |
gr.Radio(choices=["From URL", "From Saved File"], label="Save Method"),
|
| 45 |
gr.Checkbox(label="Enable JavaScript"),
|
| 46 |
],
|
| 47 |
+
outputs=[
|
| 48 |
+
gr.HTML(label="HTML Content"),
|
| 49 |
+
gr.Textbox(label="Warning/Error Messages"),
|
| 50 |
+
gr.File(label="Download HTML File")
|
| 51 |
+
],
|
| 52 |
title="Webpage to HTML Converter",
|
| 53 |
description="Convert a webpage to a single HTML file for offline use."
|
| 54 |
)
|