-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy path02_create_cu_template_audio.py
More file actions
44 lines (34 loc) · 1.35 KB
/
02_create_cu_template_audio.py
File metadata and controls
44 lines (34 loc) · 1.35 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import argparse
import sys
from pathlib import Path
from azure.identity import AzureCliCredential, get_bearer_token_provider
from content_understanding_client import AzureContentUnderstandingClient
# Get parameters from command line
p = argparse.ArgumentParser()
p.add_argument("--cu_endpoint", required=True)
p.add_argument("--cu_api_version", required=True)
args = p.parse_args()
CU_ENDPOINT = args.cu_endpoint
CU_API_VERSION = args.cu_api_version
ANALYZER_ID = "ckm-audio"
ANALYZER_TEMPLATE_FILE = 'infra/data/ckm-analyzer_config_audio.json'
# Add parent directory to path for imports
sys.path.append(str(Path.cwd().parent))
credential = AzureCliCredential(process_timeout=30)
# Initialize Content Understanding Client
token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default")
client = AzureContentUnderstandingClient(
endpoint=CU_ENDPOINT,
api_version=CU_API_VERSION,
token_provider=token_provider
)
# Create Analyzer
try:
analyzer = client.get_analyzer_detail_by_id(ANALYZER_ID)
if analyzer is not None:
client.delete_analyzer(ANALYZER_ID)
except Exception: # Analyzer may not exist yet, safe to ignore
pass
response = client.begin_create_analyzer(ANALYZER_ID, analyzer_template_path=ANALYZER_TEMPLATE_FILE)
result = client.poll_result(response)
print(f"✓ Analyzer '{ANALYZER_ID}' created")