-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (25 loc) · 959 Bytes
/
utils.py
File metadata and controls
31 lines (25 loc) · 959 Bytes
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
# utils.py
import os
import requests
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
api_key = os.getenv('api_key')
def get_random_cat():
response = requests.get(f'https://api.thecatapi.com/v1/images/search?api_key={api_key}')
cat_data = response.json()
return cat_data[0]['url']
def get_random_cat_fact():
response = requests.get(f'https://catfact.ninja/fact')
cat_data = response.json()
return cat_data['fact']
def authenticate_client():
ta_credential = AzureKeyCredential(os.getenv('AzureKeyCredential'))
text_analytics_client = TextAnalyticsClient(
endpoint=os.getenv('endpoint'),
credential=ta_credential)
return text_analytics_client
client = authenticate_client()
def sentiment_analysis_example(client, text):
document = [text]
response = client.analyze_sentiment(documents=document)[0]
return response.sentiment