Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,7 @@ def save_webpage_as_zip(url):
|
|
30 |
main_html_path = os.path.join(temp_dir, 'index.html')
|
31 |
with open(main_html_path, 'wb') as f:
|
32 |
f.write(response.content)
|
|
|
33 |
assets = []
|
34 |
for tag in soup.find_all(['img', 'link', 'script']):
|
35 |
if tag.name == 'img' and tag.get('src'):
|
@@ -49,10 +50,8 @@ def save_webpage_as_zip(url):
|
|
49 |
print(f"Skipping directory {asset_full_path}")
|
50 |
continue
|
51 |
|
52 |
-
|
53 |
os.makedirs(os.path.dirname(asset_full_path), exist_ok=True)
|
54 |
|
55 |
-
|
56 |
content = download_file(asset_url, session)
|
57 |
if content:
|
58 |
if os.path.isdir(asset_full_path):
|
@@ -84,11 +83,19 @@ def generate_zip_file(url):
|
|
84 |
f.write(zip_buffer.read())
|
85 |
return temp_zip_path
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
with gr.Blocks(theme="bethecloud/storj_theme") as demo:
|
88 |
gr.Markdown("## Webpage to ZIP Downloader 🔗")
|
89 |
gr.Markdown("Enter a URL to download the webpage and its assets as a ZIP file.")
|
90 |
-
|
91 |
-
url_input = gr.Textbox(label="Website URL", placeholder="Enter a URL (e.g., https://www.example.com)"
|
92 |
|
93 |
download_button = gr.Button("Download as ZIP")
|
94 |
output_file = gr.File(label="Download")
|
@@ -98,4 +105,12 @@ with gr.Blocks(theme="bethecloud/storj_theme") as demo:
|
|
98 |
|
99 |
download_button.click(fn=generate_zip_file, inputs=url_input, outputs=output_file)
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
main_html_path = os.path.join(temp_dir, 'index.html')
|
31 |
with open(main_html_path, 'wb') as f:
|
32 |
f.write(response.content)
|
33 |
+
|
34 |
assets = []
|
35 |
for tag in soup.find_all(['img', 'link', 'script']):
|
36 |
if tag.name == 'img' and tag.get('src'):
|
|
|
50 |
print(f"Skipping directory {asset_full_path}")
|
51 |
continue
|
52 |
|
|
|
53 |
os.makedirs(os.path.dirname(asset_full_path), exist_ok=True)
|
54 |
|
|
|
55 |
content = download_file(asset_url, session)
|
56 |
if content:
|
57 |
if os.path.isdir(asset_full_path):
|
|
|
83 |
f.write(zip_buffer.read())
|
84 |
return temp_zip_path
|
85 |
|
86 |
+
# Example URLs
|
87 |
+
examples = [
|
88 |
+
"https://www.bmw.com/en/index.html",
|
89 |
+
"https://www.ferrari.com/en-EN",
|
90 |
+
"https://streamlit.io/"
|
91 |
+
]
|
92 |
+
|
93 |
+
# Gradio Interface using Blocks API
|
94 |
with gr.Blocks(theme="bethecloud/storj_theme") as demo:
|
95 |
gr.Markdown("## Webpage to ZIP Downloader 🔗")
|
96 |
gr.Markdown("Enter a URL to download the webpage and its assets as a ZIP file.")
|
97 |
+
|
98 |
+
url_input = gr.Textbox(label="Website URL", placeholder="Enter a URL (e.g., https://www.example.com)")
|
99 |
|
100 |
download_button = gr.Button("Download as ZIP")
|
101 |
output_file = gr.File(label="Download")
|
|
|
105 |
|
106 |
download_button.click(fn=generate_zip_file, inputs=url_input, outputs=output_file)
|
107 |
|
108 |
+
# Add example URLs using gr.Examples
|
109 |
+
gr.Examples(
|
110 |
+
examples=examples,
|
111 |
+
inputs=url_input,
|
112 |
+
outputs=output_file,
|
113 |
+
fn=generate_zip_file
|
114 |
+
)
|
115 |
+
|
116 |
+
demo.launch()
|