huzaifa_arshad

Download Civitai models in Google Drive

Apr 4th, 2023 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | Source Code | 0 0
  1. #@markdown # Civitai Model Downloader
  2.  
  3. #@markdown - Download model from Civitai directly to your Google Drive
  4.  
  5. def add_files(btn):
  6.     file_name = file_name_input.value
  7.     file_url = file_url_input.value
  8.     if file_name and file_url:
  9.         file_names.append(file_name)
  10.         file_urls.append(file_url)
  11.         checkboxes.append(widgets.Checkbox(value=False, description=file_name))
  12.         clear_output()
  13.         display_files()
  14.         file_name_input.value = ''
  15.         file_url_input.value = ''
  16.  
  17. def display_files():
  18.     num_cols = 4
  19.     num_rows = len(checkboxes) // num_cols + (len(checkboxes) % num_cols > 0)
  20.     cols = [widgets.VBox(checkboxes[i*num_rows:(i+1)*num_rows]) for i in range(num_cols)]
  21.     display(widgets.HBox(cols), file_name_input, file_url_input, add_file_button, download_button)
  22.  
  23. def download_files(btn):
  24.     file_list = []
  25.     for i in range(len(checkboxes)):
  26.         if checkboxes[i].value:
  27.             file_list.append(file_urls[i])
  28.             checkboxes[i].description = f"{file_names[i]} selected"
  29.             checkboxes[i].disabled = True
  30.     if len(file_list) > 0:
  31.         output_path = "/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion"
  32.         os.makedirs(output_path, exist_ok=True)
  33.         for file_url, file_name in zip(file_list, file_names):
  34.             file_path = os.path.join(output_path, file_name)
  35.             !wget -O "$file_path" "$file_url"
  36.             clear_output()
  37.             inf('Downloaded \u2714','success', '50px')
  38.  
  39. # List of file URLs
  40. file_urls = [
  41.     "https://civitai.com/api/download/models/15236",
  42.     "https://civitai.com/api/download/models/24365",
  43.     "https://civitai.com/api/download/models/34326"
  44. ]
  45.  
  46. # List of file names
  47. file_names = [
  48.     "Deliberate.safetensors",
  49.     "DreamShaper.safetensors",
  50.     "StyleJourney.safetensors"
  51. ]
  52.  
  53. # Create the checkboxes
  54. checkboxes = [widgets.Checkbox(value=False, description=f) for f in file_names]
  55.  
  56. # Create the input fields and buttons
  57. file_name_input = widgets.Text(description='Model Name:')
  58. file_url_input = widgets.Text(description='Model URL:')
  59. add_file_button = widgets.Button(description='Add Model')
  60. add_file_button.on_click(add_files)
  61.  
  62. # Create the download button
  63. download_button = widgets.Button(description="Download Model (s)")
  64. download_button.on_click(download_files)
  65.  
  66. # Display the checkboxes and the download button in four columns
  67. display_files()
  68.  
Advertisement
Add Comment
Please, Sign In to add comment