0

I have uploaded the sentence transformer model on my blob container. The idea is to load the model into a Python notebook from the blob container. To do this I do the following:

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
service = BlobServiceClient(account_url="https://<name_of_my_blob>.blob.core.windows.net/", credential=credential)

then point to the location on the container where my model is i.e.: https://<name_of_my_blob>.blob.core.windows.net/fla-models/all-MiniLM-L6-v2,

model = SentenceTransformer(service.get_blob_to_path('fla-models/all-MiniLM-L6-v2'))

But I get

AttributeError: 'BlobServiceClient' object has no attribute 'get_blob_to_path'

I have the latest installation of azure-storage-blob. I wonder what am I doing wrong there and if the Azure lib is not longer supporting get_blob_to_path method?

Wiliam
  • 1,078
  • 10
  • 21

1 Answers1

0

I tried in my environment and got below results:

'BlobServiceClient' object has no attribute 'get_blob_to_path'

The above error tells that BlobServiceClient is not longer supporting get_blob_to_path method. because Blockblobservice is the library is using get_blob_to_path.

Example:

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')

block_blob_service.get_blob_to_path('mycontainer', 'myblockblob', 'filename')

if you need read the file in azure blob storage you can use the below code:

Code:

from  azure.storage.blob  import  BlobServiceClient
import json
service=BlobServiceClient.from_connection_string("<connection_string>")

container_client = service.get_container_client("test")
model=service.get_blob_client( "test",blob="all-MiniLM-L6-v2/modules.json"))
blob_data = model.download_blob()
data = json.loads(blob_data.readall())
print(data)
 

Console:

In portal **all-MiniLM-L6-v2**is blob name(folder), If you run only blob folder name it won't run you need use specific file name inside the folder.

enter image description here

If you need all-MiniLM-L6-v2 to get what are the files are present you can use the below code:

Code:

from  azure.storage.blob  import  BlobServiceClient

service=BlobServiceClient.from_connection_string("<connection_string>")

container_client = service.get_container_client("test")
blob_list = container_client.list_blobs()

for  blob  in  blob_list:\

print("\t" + blob.name)

Console: enter image description here

For your reference you can use this So-thread works with function.

Venkatesan
  • 3,748
  • 1
  • 3
  • 15