ERROR API text analysis

Benjamin Scemama 0 Reputation points
2023-01-25T17:30:49.0766667+00:00

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)
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,217 questions
{count} votes