Spaces:
Running
Running
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- 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 =
|
| 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('
|
| 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
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|