phyloforfun commited on
Commit
a05f4a6
1 Parent(s): 6965e7c

Major update. Support for 15 LLMs, World Flora Online taxonomy validation, geolocation, 2 OCR methods, significant UI changes, stability improvements, consistent JSON parsing

Browse files
Files changed (1) hide show
  1. vouchervision/utils_hf.py +16 -10
vouchervision/utils_hf.py CHANGED
@@ -72,15 +72,16 @@ def check_prompt_yaml_filename(fname):
72
  # Function to upload files to Google Drive
73
  def upload_to_drive(filepath, filename):
74
  # Parse the service account info from the environment variable
75
- creds_info = json.loads(os.environ.get('GDRIVE_API'))
76
  if creds_info:
 
77
  creds = service_account.Credentials.from_service_account_info(
78
  creds_info, scopes=["https://www.googleapis.com/auth/drive"]
79
  )
80
  service = build('drive', 'v3', credentials=creds)
81
 
82
  # Get the folder ID from the environment variable
83
- folder_id = os.environ.get('GDRIVE')
84
 
85
  if folder_id:
86
  file_metadata = {
@@ -94,12 +95,17 @@ def upload_to_drive(filepath, filename):
94
  elif filename.endswith('.zip'):
95
  mimetype = 'application/zip'
96
  else:
97
- mimetype = None # or set a default mimetype
 
 
98
 
99
- if mimetype:
100
- media = MediaFileUpload(filepath, mimetype=mimetype)
101
- service.files().create(
102
- body=file_metadata,
103
- media_body=media,
104
- fields='id'
105
- ).execute()
 
 
 
 
72
  # Function to upload files to Google Drive
73
  def upload_to_drive(filepath, filename):
74
  # Parse the service account info from the environment variable
75
+ creds_info = os.environ.get('GDRIVE_API')
76
  if creds_info:
77
+ creds_info = json.loads(creds_info)
78
  creds = service_account.Credentials.from_service_account_info(
79
  creds_info, scopes=["https://www.googleapis.com/auth/drive"]
80
  )
81
  service = build('drive', 'v3', credentials=creds)
82
 
83
  # Get the folder ID from the environment variable
84
+ folder_id = os.environ.get('GDRIVE_FOLDER_ID') # Renamed for clarity
85
 
86
  if folder_id:
87
  file_metadata = {
 
95
  elif filename.endswith('.zip'):
96
  mimetype = 'application/zip'
97
  else:
98
+ # Set a default mimetype if desired or handle the unsupported file type
99
+ print("Unsupported file type")
100
+ return None
101
 
102
+ # Upload the file
103
+ media = MediaFileUpload(filepath, mimetype=mimetype)
104
+ file = service.files().create(
105
+ body=file_metadata,
106
+ media_body=media,
107
+ fields='id'
108
+ ).execute()
109
+ print(f"Uploaded file with ID: {file.get('id')}")
110
+ else:
111
+ print("GDRIVE_API environment variable not set.")