Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,61 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
|
4 |
logs = []
|
5 |
|
6 |
def downloader(url, output_path, civitai_token):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
with gr.Blocks(title
|
14 |
gr.Markdown("<h1> ⬇️ CivitAI Downloader ⬇️ </h1>")
|
15 |
-
gr.Markdown(f" gradio demo by [Eddycrack864](https://github.com/Eddycrack864)")
|
16 |
|
17 |
with gr.Row():
|
18 |
link = gr.Textbox(
|
19 |
-
label
|
20 |
-
placeholder
|
21 |
-
interactive
|
22 |
)
|
23 |
out_path = gr.Textbox(
|
24 |
-
label
|
25 |
-
placeholder
|
26 |
-
interactive
|
27 |
-
value = "/home/user/app"
|
28 |
)
|
|
|
29 |
with gr.Row():
|
30 |
token = gr.Textbox(
|
31 |
-
label
|
32 |
-
placeholder
|
33 |
-
interactive
|
34 |
)
|
|
|
35 |
with gr.Row():
|
36 |
-
button = gr.Button("Download!", variant
|
|
|
37 |
with gr.Row():
|
38 |
outputs = gr.Textbox(
|
39 |
-
label
|
40 |
-
interactive
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
|
|
44 |
|
45 |
-
app.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import time
|
4 |
|
5 |
logs = []
|
6 |
|
7 |
def downloader(url, output_path, civitai_token):
|
8 |
+
logs.clear()
|
9 |
+
prompt = f"civitai-downloader --url={url} --output_path={output_path} --token={civitai_token}"
|
10 |
+
os.system(prompt)
|
11 |
+
logs.append(f"Download initiated! Check the output path: {output_path}")
|
12 |
+
|
13 |
+
# Check if the downloaded file exists in the output path
|
14 |
+
for _ in range(10): # retry for a certain amount of time
|
15 |
+
time.sleep(1) # wait a bit before checking
|
16 |
+
if os.path.exists(output_path):
|
17 |
+
logs.append(f"File detected at: {output_path}")
|
18 |
+
return "\n".join(logs), output_path # Return path for file output
|
19 |
+
else:
|
20 |
+
logs.append("Download complete, but file not detected in the specified output path.")
|
21 |
+
return "\n".join(logs), None # Return None if file is not detected
|
22 |
|
23 |
+
with gr.Blocks(title="CivitAI Downloader") as app:
|
24 |
gr.Markdown("<h1> ⬇️ CivitAI Downloader ⬇️ </h1>")
|
|
|
25 |
|
26 |
with gr.Row():
|
27 |
link = gr.Textbox(
|
28 |
+
label="URL",
|
29 |
+
placeholder="Paste the URL here",
|
30 |
+
interactive=True,
|
31 |
)
|
32 |
out_path = gr.Textbox(
|
33 |
+
label="Output Path",
|
34 |
+
placeholder="Place the output path here",
|
35 |
+
interactive=True,
|
|
|
36 |
)
|
37 |
+
|
38 |
with gr.Row():
|
39 |
token = gr.Textbox(
|
40 |
+
label="CivitAI API Key",
|
41 |
+
placeholder="Paste the API Key here. Only needed the first time per session",
|
42 |
+
interactive=True,
|
43 |
)
|
44 |
+
|
45 |
with gr.Row():
|
46 |
+
button = gr.Button("Download!", variant="primary")
|
47 |
+
|
48 |
with gr.Row():
|
49 |
outputs = gr.Textbox(
|
50 |
+
label="Output information",
|
51 |
+
interactive=False,
|
52 |
+
)
|
53 |
+
file_output = gr.File(
|
54 |
+
label="Downloaded File",
|
55 |
+
interactive=False,
|
56 |
+
)
|
57 |
|
58 |
+
# Use both `outputs` and `file_output` for the button click event
|
59 |
+
button.click(downloader, [link, out_path, token], [outputs, file_output])
|
60 |
|
61 |
+
app.launch(share=True)
|