File size: 2,063 Bytes
605b44a
2f5ee80
7c1fc84
605b44a
2f5ee80
605b44a
2f5ee80
7c1fc84
 
 
 
 
 
 
 
 
 
 
 
 
 
605b44a
e9ce6f4
2f5ee80
ebb5fa6
 
 
7c1fc84
 
 
ebb5fa6
 
7c1fc84
 
 
ebb5fa6
7c1fc84
ebb5fa6
 
7c1fc84
 
 
ebb5fa6
7c1fc84
ebb5fa6
7c1fc84
 
ebb5fa6
 
7c1fc84
 
 
b602a76
7c1fc84
 
 
 
2f5ee80
7c1fc84
 
2f5ee80
7c1fc84
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import os
import time

logs = []

def downloader(url, output_path, civitai_token):
    logs.clear()
    prompt = f"civitai-downloader --url={url} --output_path={output_path} --token={civitai_token}"
    os.system(prompt)
    logs.append(f"Download initiated! Check the output path: {output_path}")
    
    # Check if the downloaded file exists in the output path
    for _ in range(10):  # retry for a certain amount of time
        time.sleep(1)  # wait a bit before checking
        if os.path.exists(output_path):
            logs.append(f"File detected at: {output_path}")
            return "\n".join(logs), output_path  # Return path for file output
    else:
        logs.append("Download complete, but file not detected in the specified output path.")
        return "\n".join(logs), None  # Return None if file is not detected

with gr.Blocks(theme='Ryouko-Yamanda65777/ryo', title="CivitAI Downloader") as app:
    gr.Markdown("<h1> ⬇️ CivitAI Downloader ⬇️ </h1>")
    
    with gr.Row():
        link = gr.Textbox(
            label="URL",
            placeholder="Paste the URL here",
            interactive=True,
        )
        out_path = gr.Textbox(
            label="Output Path",
            placeholder="Place the output path here",
            interactive=True,
        )
    
    with gr.Row():
        token = gr.Textbox(
            label="CivitAI API Key",
            placeholder="Paste the API Key here. Only needed the first time per session",
            interactive=True,
        )
    
    with gr.Row():
        button = gr.Button("Download!", variant="primary")
    
    with gr.Row():
        outputs = gr.Textbox(
            label="Output information",
            interactive=False,
        )
    with gr.Row():
        file_output = gr.File(
            label="Downloaded File",
            interactive=False,
        )

    # Use both `outputs` and `file_output` for the button click event
    button.click(downloader, [link, out_path, token], [outputs, file_output])

app.launch(share=True)