Spaces:
Build error
Build error
File size: 1,401 Bytes
ec755ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# google_drive.py
from google.colab import drive
from google.colab import auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
import os
def authenticate_and_get_path():
# authenticate user
auth.authenticate_user()
# mount Google Drive
drive.mount('/content/gdrive')
# get folder name from user input
folder_name = input("Enter the name of the folder containing the model: ")
# search for folder with given name
folder_id = search_folder(folder_name)
# check if folder was found
if folder_id is None:
print("Error: Folder not found.")
return None
# create path to model
path = os.path.join("/content/gdrive/MyDrive", folder_id)
return path
def search_folder(name):
# create Drive API client
service = build('drive', 'v3', developerKey='YOUR_API_KEY')
# search for folders with given name
query = "mimeType='application/vnd.google-apps.folder' and trashed=false and name='" + name + "'"
results = service.files().list(q=query, fields="nextPageToken, files(id, name)").execute()
# check if folder was found
items = results.get("files", [])
if len(items) == 0:
return None
elif len(items) > 1:
print("Warning: Multiple folders found with name '" + name + "'. Using first folder.")
folder_id = items[0]["id"]
return folder_id |