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()