-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgcs_helper.py
33 lines (24 loc) · 1.05 KB
/
gcs_helper.py
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
from google.cloud import storage
BUCKET_NAME = "glove-tf-model"
MODEL_FNAME = "glove_model.txt"
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client("sunway-14050926")
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
def download_blob(bucket_name, source_blob_name, destination_file_name):
import pathlib
"""Downloads a blob from the bucket."""
if not pathlib.Path(destination_file_name).exists():
storage_client = storage.Client("sunway-14050926")
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print('Blob {} downloaded to {}.'.format(
source_blob_name,
destination_file_name))
return destination_file_name