ERROR API text analysis
Benjamin Scemama
0
Reputation points
Hello. I would like to use the text analysis api of microsoft azure to extract keywords from a text and also to make a summary of the same text. However I have an error. Could someone help me to solve it? (my text document is called 'subtitles_text')
Thanks
# Utilisation de l'API Analyse de Texte de Microsoft Azure pour générer des phrases clés
subscription_key = "MYAPIKEY"
endpoint = "https://atvyt.cognitiveservices.azure.com/"
headers = {"Ocp-Apim-Subscription-Key": subscription_key}
data = {"documents": [{"id": "1", "language": "fr", "text": subtitles_text}]}
response = requests.post(endpoint, headers=headers, json=data)
key_phrases = json.loads(response.text)["documents"][0]["key_phrases"]
summary = json.loads(response.text)["documents"][0]["summary"]
# Enregistrement des phrases clés dans un fichier .txt
with open("phrases_cles.txt", "w") as f:
f.write(key_phrases)
# Enregistrement du résumer dans un fichier .txt
with open("resumer.txt", "w") as f:
f.write(summary)
KeyError Traceback (most recent call last)
Sign in to answer