1

I am trying to connect and Mount multiple Google Drive account with Google Colab. So, qDiffusion Application load file from both Google Drive account and show in the client app

Github Repo for reference : https://github.com/arenasys/qDiffusion

Original Code (Notebook URL):

%cd /content
import IPython.display
import os
import sys

if not os.path.exists("/content/sd-inference-server"):
    !git clone https://github.com/arenasys/sd-inference-server.git

%cd /content/sd-inference-server
model_folder = "/content/sd-inference-server/models"
try:
    # decline the popup to use the local folder ^
    from google.colab import drive
    drive.mount('/content/drive', force_remount=True)
    model_folder = "/content/drive/My Drive/qDiffusion/models"
    if not os.path.exists(model_folder):
        !mkdir '/content/drive/My Drive/qDiffusion' -p
        !cp -r 'models/' '/content/drive/My Drive/qDiffusion/'
except Exception as e:
    pass

if not os.path.exists("venv"):
    !curl -OJL https://huggingface.co/datasets/arenasys/qDiffusion/resolve/main/cached_venv5.tar
    !tar xf cached_venv5.tar; mv cached_venv5 venv; rm cached_venv5.tar
    !rm /content/sd-inference-server/venv/lib/python3.10/site-packages/pathlib.py
    !pip install timm==0.6.13
    !pip install tomesd==0.1.3
    !pip install torchmetrics
    !pip uninstall -y tensorflow

    !wget http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb
    !apt install -qq libunwind8-dev
    !dpkg -i *.deb
    %env LD_PRELOAD=libtcmalloc.so

    IPython.display.clear_output()

if not sys.path[0] == "/content/sd-inference-server/":
    sys.path.insert(0, "/content/sd-inference-server/venv/lib/python3.10/site-packages")
    sys.path.insert(0, "/content/sd-inference-server/")

from pycloudflared import try_cloudflare
tunnel_url = try_cloudflare(port=28888, verbose=False)
print("ENDPOINT:", tunnel_url.tunnel.replace("https", "wss"))

!python remote.py "$model_folder"

try_cloudflare.terminate(28888)

Multiple Mount Code (Solution from Stackoverflow) :

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
!mkdir -p /drive2
!google-drive-ocamlfuse /drive2

After Merging, i am trying Like :

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse

from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials

# Define a function to connect and mount Google Drive
def mount_drive():
    creds = GoogleCredentials.get_application_default()
    import getpass
    vcode = getpass.getpass()
    !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} -code={vcode}

# Define a function to mount a specific Google Drive account
def mount_google_drive(account_name, drive_path):
    # Create a folder to mount the drive
    mount_folder = f"/drive_{account_name}"
    !mkdir -p {mount_folder}
    # Mount the drive
    !google-drive-ocamlfuse {mount_folder}
    # Move the contents to the desired drive path
    !mv {mount_folder}/* {drive_path}
    # Remove the empty folder
    !rm -rf {mount_folder}

# Example usage:
mount_drive()

# Mount and specify the accounts and paths
accounts = [
    {"name": "account1", "drive_path": "/content/drive/My Drive/qDiffusion/models"},
    {"name": "account2", "drive_path": "/content/drive/My Drive/other_drive"}
]

for account in accounts:
    print(f"Mounting {account['name']}...")
    mount_google_drive(account["name"], account["drive_path"])
    print(f"{account['name']} mounted at {account['drive_path']}")

%cd /content
import IPython.display
import os
import sys

if not os.path.exists("/content/sd-inference-server"):
    !git clone https://github.com/arenasys/sd-inference-server.git

%cd /content/sd-inference-server
model_folder = "/content/sd-inference-server/models"
try:
    # decline the popup to use the local folder ^
    from google.colab import drive
    drive.mount('/content/drive', force_remount=True)
    model_folder = "/content/drive/My Drive/qDiffusion/models"
    if not os.path.exists(model_folder):
        !mkdir '/content/drive/My Drive/qDiffusion' -p
        !cp -r 'models/' '/content/drive/My Drive/qDiffusion/'
except Exception as e:
    pass

if not os.path.exists("venv"):
    !curl -OJL https://huggingface.co/datasets/arenasys/qDiffusion/resolve/main/cached_venv5.tar
    !tar xf cached_venv5.tar; mv cached_venv5 venv; rm cached_venv5.tar
    !rm /content/sd-inference-server/venv/lib/python3.10/site-packages/pathlib.py
    !pip install timm==0.6.13
    !pip install tomesd==0.1.3
    !pip install torchmetrics
    !pip uninstall -y tensorflow

    !wget http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb
    !wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb
    !apt install -qq libunwind8-dev
    !dpkg -i *.deb
    %env LD_PRELOAD=libtcmalloc.so

    IPython.display.clear_output()

if not sys.path[0] == "/content/sd-inference-server/":
    sys.path.insert(0, "/content/sd-inference-server/venv/lib/python3.10/site-packages")
    sys.path.insert(0, "/content/sd-inference-server/")

from pycloudflared import try_cloudflare
tunnel_url = try_cloudflare(port=28888, verbose=False)
print("ENDPOINT:", tunnel_url.tunnel.replace("https", "wss"))

!python remote.py "$model_folder"

try_cloudflare.terminate(28888)

It not working as expected. No popup to connect different Google Drive account and No EndPoint TryCloudflare Public URL.

Mehul Kumar
  • 461
  • 8

0 Answers0