diff --git a/final_project/README.md b/final_project/README.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/final_project/README.md @@ -0,0 +1 @@ + diff --git a/final_project/emotion_detection.py b/final_project/emotion_detection.py new file mode 100644 index 000000000..47a20e472 --- /dev/null +++ b/final_project/emotion_detection.py @@ -0,0 +1,16 @@ +import requests + +def emotion_detector(text_to_analyze): + url = 'https://sn-watson-emotion.labs.skills.network/v1/watson.runtime.nlp.v1/NlpService/EmotionPredict' + headers = { + "Content-Type": "application/json", + "grpc-metadata-mm-model-id": "emotion_aggregated-workflow_lang_en_stock" + } + input_json = { "raw_document": { "text": text_to_analyze } } + + response = requests.post(url, json=input_json, headers=headers) + if response.status_code == 200: + result = response.json() + return result['emotionPredictions'][0]['emotion'] + else: + return f"Request failed with status code: {response.status_code}"