Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from io import BytesIO
|
4 |
+
from zipfile import ZipFile
|
5 |
+
|
6 |
+
def urls_to_zip(urls_text):
|
7 |
+
urls = urls_text.strip().split("\n")
|
8 |
+
zip_buffer = BytesIO()
|
9 |
+
|
10 |
+
with ZipFile(zip_buffer, "w") as zip_file:
|
11 |
+
for i, url in enumerate(urls):
|
12 |
+
url = url.strip()
|
13 |
+
if not url:
|
14 |
+
continue
|
15 |
+
try:
|
16 |
+
response = requests.get(url)
|
17 |
+
response.raise_for_status()
|
18 |
+
filename = url.split("/")[-1] or f"file_{i}"
|
19 |
+
zip_file.writestr(filename, response.content)
|
20 |
+
except Exception as e:
|
21 |
+
# γ¨γ©γΌγγγγ°γγ‘γ€γ«εγ«γ¨γ©γΌζ
ε ±γε
₯γγοΌδ»»ζοΌ
|
22 |
+
zip_file.writestr(f"error_{i}.txt", f"Failed to download {url}\nError: {str(e)}")
|
23 |
+
|
24 |
+
zip_buffer.seek(0)
|
25 |
+
return zip_buffer
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("### ζΉθ‘γ§εΊεγ£γURLγͺγΉγγγZIPγδ½ζγγΎγ")
|
29 |
+
url_input = gr.Textbox(lines=10, placeholder="γγγ«URLγζΉθ‘εΊεγγ§ε
₯εγγ¦γγ γγ")
|
30 |
+
zip_output = gr.File(label="ZIPγγ‘γ€γ«")
|
31 |
+
btn = gr.Button("ZIPδ½ζ")
|
32 |
+
|
33 |
+
btn.click(urls_to_zip, inputs=url_input, outputs=zip_output)
|
34 |
+
|
35 |
+
demo.launch()
|