Let's start off with initializing a service instance. Just like the Tone Analyzer, there's no need for the Personality Insights service to have any tooling:
- We start by importing the API:
from ibm_watson import PersonalityInsightsV3
- Then, you simply feed in text after initializing the service:
personality_insights = PersonalityInsightsV3(version="2017-10-13", iam_apikey="W73kz6O3XR1pkIQVn2RYbrrtIU2o0IvNYuqiMICwSwro")
- Next, create a file called
personality.txt
, a simple text file containing the text from which you wish to infer personality traits. Then, you load the contents of that file into theprofile_text
variable:
profile_text = open("personality.txt").read()
- You call the
profile
function on thepersonality_insights
instance and callget_result()
in order to get the JSON output of the service:
profile = personality_insights.profile(profile_text, "text/plain").get_result()
- You can then format the output nicely using the following code:
needs = profile["needs...