Ryouko65777 commited on
Commit
7c1fc84
·
verified ·
1 Parent(s): ebb5fa6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -23
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
- logs.clear()
8
- prompt = f"civitai-downloader --url={url} --output_path={output_path} --token={civitai_token}"
9
- os.system(prompt)
10
- logs.append(f"Downloaded! Check the output path: {output_path}")
11
- yield "\n".join(logs)
 
 
 
 
 
 
 
 
 
12
 
13
- with gr.Blocks(title = "CivitAI Downloader") as app:
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 = "URL",
20
- placeholder = "Paste the URL here",
21
- interactive = True,
22
  )
23
  out_path = gr.Textbox(
24
- label = "Output Path",
25
- placeholder = "Place the output path here",
26
- interactive = False,
27
- value = "/home/user/app"
28
  )
 
29
  with gr.Row():
30
  token = gr.Textbox(
31
- label = "CivitAI API Key",
32
- placeholder = "Paste the API Key here. Only needed the first time per session",
33
- interactive = True,
34
  )
 
35
  with gr.Row():
36
- button = gr.Button("Download!", variant = "primary")
 
37
  with gr.Row():
38
  outputs = gr.Textbox(
39
- label = "Output information",
40
- interactive = False,
41
- )
 
 
 
 
42
 
43
- button.click(downloader, [link, out_path, token], [outputs])
 
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)