Spaces:
Sleeping
Sleeping
File size: 1,337 Bytes
464d134 1f09515 464d134 1f09515 464d134 1f09515 464d134 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
import requests
from io import BytesIO
from zipfile import ZipFile
import tempfile
import os
def urls_to_zip(urls_text):
urls = urls_text.strip().split("\n")
# δΈζγγ‘γ€γ«γδ½ζ
with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as tmp:
with ZipFile(tmp, "w") as zip_file:
for i, url in enumerate(urls):
url = url.strip()
if not url:
continue
try:
response = requests.get(url)
response.raise_for_status()
filename = url.split("/")[-1] or f"file_{i}"
zip_file.writestr(filename, response.content)
except Exception as e:
zip_file.writestr(f"error_{i}.txt", f"Failed to download {url}\nError: {str(e)}")
tmp_path = tmp.name
return tmp_path # γγ‘γ€γ«γγΉγθΏγ
with gr.Blocks() as demo:
gr.Markdown("### ζΉθ‘γ§εΊεγ£γURLγͺγΉγγγZIPγδ½ζγγΎγ")
url_input = gr.Textbox(lines=10, placeholder="γγγ«URLγζΉθ‘εΊεγγ§ε
₯εγγ¦γγ γγ")
zip_output = gr.File(label="ZIPγγ‘γ€γ«")
btn = gr.Button("ZIPδ½ζ")
btn.click(urls_to_zip, inputs=url_input, outputs=zip_output)
demo.launch()
|