I'm building a Streamlit app that reads a file (a .npy file in this case) from Azure Blob Storage. I'm accessing the storage account by specifying the account name, account key, container name, and blob name (file name) in a function I've defined as read_blob_content. For some reason however I get this error when running the app:
FileNotFoundError: [Errno 2] No such file or directory: 'file.npy'
Traceback:
File "C:\Users...\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 535, in _run_script
exec(code, module.__dict__)
File "C:\Users...\app\main.py", line 34, in <module>
v3_embedding = np.load(read_blob_content(account_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users...\Lib\site-packages\numpy\lib\npyio.py", line 427, in load
fid = stack.enter_context(open(os_fspath(file), "rb"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
To me, this seems to indicate that I am somehow entering the path wrong even though the file name matches what is on my Azure Blob Storage account. Does anybody know what I am doing wrong?
Here is the code for additional context:
In main.py
v3_embedding = np.load(read_blob_content(account_name,
account_key,
container_name,
blob_name))
The read_blob_content function:
def read_blob_content(storage_account_name, storage_account_key, container_name, blob_name):
'''Reads files stored on Azure blob storage container'''
# Create a BlobServiceClient
blob_service_client = BlobServiceClient(account_url=f"https://{storage_account_name}.blob.core.windows.net", credential=storage_account_key)
# Get the blob content as a stream
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
# Get the blob content as a stream
blob_stream = blob_client.download_blob()
# Read the content from the stream
blob_content = blob_stream.readall().decode('utf-8')
return blob_content
I tried the following code to read a .npy blob data from Azure Blob Storage using a Streamlit app:
Code :
read_blob.py :
Output :
The Streamlit app code ran successfully, as shown below:
The Streamlit app read the .npy blob file data in the browser, as displayed below.