** Install Chrome ** Search for [Google Chrome] and install Chrome ** Install Collaboratory in Google Drive ** Right-click in an empty drive and click Add App Enter [Colaboratry] in the search field and click the app Install! !! Right-click on the empty drive again and click [Google Colabora try] If the following screen is displayed, the setting is complete !! (I will code here.)
** IBM Cloud settings ** Jump to the IBM Cloud page !! If you have an account, please log in, otherwise register a new one. After clicking [Catalog] at the top of the screen, enter [Personality Insigts] in the search field to display the screen below, and click [Personality Insigts]. ** Enter each item ** Make the settings on the page you jumped to as follows. --Regional selection --Tokyo (Not specified, but changes will occur in later coding)
Please open Google Colaboratry and build an environment where you can code (please use the screen below).
coding
PersonalityInsights.ipynb
!pip install ibm_watson #Install missing modules in Colab environment
#Import of required messages
import json #Import json parsing module
from ibm_watson import PersonalityInsightsV3 # PersonalityInsights
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from os.path import join, dirname
def analyze_personality():
#------------------------------input----------------------------------
authenticator = IAMAuthenticator('XXXXXXXX') #Enter API key
#---------------------------------------------------------------------
service = PersonalityInsightsV3(
version='2018-10-30',
authenticator= authenticator)
#------------------------------input----------------------------------
service.set_service_url('XXXXXXXXXX') #Enter the URL
#--------------------------------------------------------------------
#Analyze personality
with open('XXXXXXX.txt', 'r') as profile_text: #Specify the txt file you want to analyze with an absolute path
profile = service.profile(
profile_text.read(),
'application/json',
content_language='ja',
accept_language='ja').get_result()
#Write to file
with open('/content/result.json', 'w') as resultFile:
json.dump(profile, resultFile, ensure_ascii=False, indent=2)
analyze_personality() #Execute function
Copy the ** API key ** and ** URL ** you wrote down earlier to the designated location.
Click [Runtime] in the tab at the top of the Colaboratry screen, and then click [Run All Cells]. Click the file mark on the tab on the left side of the screen, and if the json file is generated in the specified directory under the cloud environment, it is successful.
Please let me know if there is anything
Recommended Posts