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

⬇️ CivitAI Downloader ⬇️

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