33-AzureML-2/azuremlpythonsdk-v2/data_tabular.py

32 lines
793 B
Python
Raw Normal View History

2024-09-04 10:15:43 +02:00
"""
Script to create and register file as an uri
"""
from azure.ai.ml.constants import AssetTypes
from azure.ai.ml.entities import Data
from ml_client import create_or_load_ml_client
name_dataset = "diabetes-dataset"
data_folder = "./data/diabetes.csv"
2024-09-04 10:15:43 +02:00
def create_tabular_dataset():
# 1. Create or Load a ML client
2024-09-05 10:15:50 +02:00
ml_client = create_or_load_ml_client()
2024-09-04 10:15:43 +02:00
# 2. Add files
2024-09-05 10:15:50 +02:00
if name_dataset not in [id for env in ml_client.data.list()]:
2024-09-04 10:15:43 +02:00
tab_data_set = Data(
2024-09-05 10:15:50 +02:00
path=data_folder,
2024-09-04 10:15:43 +02:00
type=AssetTypes.URI_FILE,
name=name_dataset,
)
2024-09-05 10:15:50 +02:00
ml_client.data.create_or_update(tab_data_set)
2024-09-04 10:15:43 +02:00
else:
print("Dataset already registered.")
if __name__ == "__main__":
create_tabular_dataset()