Spaces:
Build error
Build error
# 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 |