ComfyUI
ComfyUI copied to clipboard
[Question] Just save the generated photos on Google Colab to the gdrive automatically
Hi. Is there any way to make the generated images automatically save to GDrive without necessarily having to use GDrive to store all the content from Colab? That way, only the generated photos would go to my GDrive, avoiding the need to install Colab directly through it and fill up my GDrive space. Is it possible? Thanks!
if you use SaveImage node it will save to output folder, if you use PreviewImage node it will save to temp folder. And temp folder will be deleted when ComfyUI startup.
bottom line: If you mount google drive and ComfyUI placed in there it will be saved there.
That's the problem, when you mount on GDrive, all the downloaded content in Comfyui like checkpoints, etc., goes to GDrive and it exceeds the storage limit. I just want the output of the photos to go to my GDrive automatically because if I leave it generating lots of photos for a long time, I run the risk of Google Colab stopping due to the Colab limit, and I lose everything that was generated. The only way I'm currently using is manually transferring the content generated in Comfyui to my GDrive using the cell below, but unfortunately I have to keep interrupting the local tunnel to execute the cell to make the backup:
from google.colab import drive import shutil
drive.mount('/content/drive')
source_directory = '/content/ComfyUI/output' destination_directory = '/content/drive/MyDrive/ComfyUI/output'
shutil.copytree(source_directory, destination_directory, dirs_exist_ok=True)
use this argument when starting comfyui to set the output directory: --output-directory
It worked, thank you. I also took the liberty of adding the option to choose whether or not to save the photos directly to Google Drive. Maybe it would be a good idea to implement this option in Colab for users to choose on localtunnel. Tks.
#@title Run ComfyUI with localtunnel (Recommended Way) !npm install -g localtunnel
import subprocess import threading import time import socket import urllib.request
def iframe_thread(port): while True: time.sleep(0.5) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex(('127.0.0.1', port)) if result == 0: break sock.close() print("\nComfyUI finished loading, trying to launch localtunnel (if it gets stuck here localtunnel is having issues)\n")
print("The password/enpoint ip for localtunnel is:", urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip("\n")) p = subprocess.Popen(["lt", "--port", "{}".format(port)], stdout=subprocess.PIPE) for line in p.stdout: print(line.decode(), end='')
threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()
OPTIONS = {}
OUTPUT_TO_GOOGLE_DRIVE = False #@param {type:"boolean"} OPTIONS['OUTPUT_TO_GOOGLE_DRIVE'] = OUTPUT_TO_GOOGLE_DRIVE
if OPTIONS['OUTPUT_TO_GOOGLE_DRIVE']: # Mount Google Drive print("Mounting Google Drive...") from google.colab import drive drive.mount('/content/drive')
# Code to save the output to Google Drive
output_directory = '/content/drive/MyDrive/ComfyUI/output'
print(f"Saving output to: {output_directory}")
!python main.py --output-directory {output_directory}
else: # Code to not save the output print("Not saving output to Google Drive") !python main.py --dont-print-server