Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
def save_webpage(url, save_method, javascript):
|
| 5 |
+
# Command to execute
|
| 6 |
+
command = ["python", "webpage2html.py"]
|
| 7 |
+
|
| 8 |
+
if javascript:
|
| 9 |
+
command.append("-s")
|
| 10 |
+
|
| 11 |
+
command.append(url)
|
| 12 |
+
|
| 13 |
+
if save_method == "From URL":
|
| 14 |
+
command_str = " ".join(command) + " > output.html"
|
| 15 |
+
else:
|
| 16 |
+
command.append(f"/path/to/{url}")
|
| 17 |
+
command_str = " ".join(command) + " > something_single.html"
|
| 18 |
+
|
| 19 |
+
# Execute the command
|
| 20 |
+
subprocess.run(command_str, shell=True)
|
| 21 |
+
|
| 22 |
+
return "Webpage saved successfully!"
|
| 23 |
+
|
| 24 |
+
# Gradio Interface
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=save_webpage,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.inputs.Textbox(label="URL"),
|
| 29 |
+
gr.inputs.Radio(choices=["From URL", "From Saved File"], label="Save Method"),
|
| 30 |
+
gr.inputs.Checkbox(label="Enable JavaScript"),
|
| 31 |
+
],
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="Webpage to HTML Converter",
|
| 34 |
+
description="Convert a webpage to a single HTML file for offline use."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
iface.launch()
|