Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,8 +39,7 @@ def save_webpage_as_zip(url):
|
|
39 |
assets.append(tag['href'])
|
40 |
elif tag.name == 'script' and tag.get('src'):
|
41 |
assets.append(tag['src'])
|
42 |
-
|
43 |
-
# Download and save all assets
|
44 |
for asset in assets:
|
45 |
asset_url = urljoin(url, asset)
|
46 |
asset_path = urlparse(asset_url).path.lstrip('/')
|
@@ -59,7 +58,7 @@ def save_webpage_as_zip(url):
|
|
59 |
continue
|
60 |
with open(asset_full_path, 'wb') as f:
|
61 |
f.write(content)
|
62 |
-
|
63 |
zip_buffer = BytesIO()
|
64 |
with ZipFile(zip_buffer, 'w') as zipf:
|
65 |
for root, _, files in os.walk(temp_dir):
|
@@ -71,7 +70,6 @@ def save_webpage_as_zip(url):
|
|
71 |
for file in files:
|
72 |
os.remove(os.path.join(root, file))
|
73 |
os.rmdir(root)
|
74 |
-
|
75 |
zip_buffer.seek(0)
|
76 |
return zip_buffer
|
77 |
|
@@ -83,14 +81,12 @@ def generate_zip_file(url):
|
|
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.")
|
@@ -105,12 +101,10 @@ with gr.Blocks(theme="bethecloud/storj_theme") as demo:
|
|
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()
|
|
|
39 |
assets.append(tag['href'])
|
40 |
elif tag.name == 'script' and tag.get('src'):
|
41 |
assets.append(tag['src'])
|
42 |
+
|
|
|
43 |
for asset in assets:
|
44 |
asset_url = urljoin(url, asset)
|
45 |
asset_path = urlparse(asset_url).path.lstrip('/')
|
|
|
58 |
continue
|
59 |
with open(asset_full_path, 'wb') as f:
|
60 |
f.write(content)
|
61 |
+
|
62 |
zip_buffer = BytesIO()
|
63 |
with ZipFile(zip_buffer, 'w') as zipf:
|
64 |
for root, _, files in os.walk(temp_dir):
|
|
|
70 |
for file in files:
|
71 |
os.remove(os.path.join(root, file))
|
72 |
os.rmdir(root)
|
|
|
73 |
zip_buffer.seek(0)
|
74 |
return zip_buffer
|
75 |
|
|
|
81 |
f.write(zip_buffer.read())
|
82 |
return temp_zip_path
|
83 |
|
|
|
84 |
examples = [
|
85 |
"https://www.bmw.com/en/index.html",
|
86 |
"https://www.ferrari.com/en-EN",
|
87 |
"https://streamlit.io/"
|
88 |
]
|
89 |
|
|
|
90 |
with gr.Blocks(theme="bethecloud/storj_theme") as demo:
|
91 |
gr.Markdown("## Webpage to ZIP Downloader 🔗")
|
92 |
gr.Markdown("Enter a URL to download the webpage and its assets as a ZIP file.")
|
|
|
101 |
|
102 |
download_button.click(fn=generate_zip_file, inputs=url_input, outputs=output_file)
|
103 |
|
|
|
104 |
gr.Examples(
|
105 |
examples=examples,
|
106 |
inputs=url_input,
|
107 |
outputs=output_file,
|
108 |
fn=generate_zip_file
|
109 |
)
|
110 |
+
demo.launch()
|
|