Skip to content

Commit a8cd58b

Browse files
authored
Merge pull request #79 from Azure-Samples/aahill-patch-1
Update text_analytics_samples.py
2 parents ecd4386 + 5647e4e commit a8cd58b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

samples/language/text_analytics_samples.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
# </imports>
88

99
# <initialVars>
10-
key = "<paste-your-text-analytics-key-here>"
11-
endpoint = "<paste-your-text-analytics-endpoint-here>"
10+
key_var_name = 'TEXT_ANALYTICS_SUBSCRIPTION_KEY'
11+
if not key_var_name in os.environ:
12+
raise Exception('Please set/export the environment variable: {}'.format(key_var_name))
13+
subscription_key = os.environ[key_var_name]
14+
15+
endpoint_var_name = 'TEXT_ANALYTICS_ENDPOINT'
16+
if not endpoint_var_name in os.environ:
17+
raise Exception('Please set/export the environment variable: {}'.format(endpoint_var_name))
18+
endpoint = os.environ[endpoint_var_name]
1219
# </initialVars>
1320

1421
# <authentication>
1522
def authenticateClient():
16-
credentials = CognitiveServicesCredentials(key)
23+
credentials = CognitiveServicesCredentials(subscription_key)
1724
text_analytics_client = TextAnalyticsClient(
1825
endpoint=endpoint, credentials=credentials)
1926
return text_analytics_client

0 commit comments

Comments
 (0)