Share via

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)
Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.