Create a personality diagnostic tool in a cloud environment using Google Colaboratory and IBM Watson Personality Insights

Google Colaboratry settings

** Install Chrome ** Search for [Google Chrome] and install Chrome ** Install Collaboratory in Google Drive ** Right-click in an empty drive and click Add App Colab.png Enter [Colaboratry] in the search field and click the app Colab2.png Install! !! Colab3.png Right-click on the empty drive again and click [Google Colabora try] Colab4.png If the following screen is displayed, the setting is complete !! (I will code here.) Colab5.png

IBM Watson Personality Insights Settings

** 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]. personality.png ** 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)

Programming with Python

Please open Google Colaboratry and build an environment where you can code (please use the screen below). Colab5.png

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.

Run

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.

Thank you for your hard work

Please let me know if there is anything

Recommended Posts

Create a personality diagnostic tool in a cloud environment using Google Colaboratory and IBM Watson Personality Insights
Tips for using Selenium and Headless Chrome in a CUI environment
[Python] Create a Batch environment using AWS-CDK
Create a REST API using the model learned in Lobe and TensorFlow Serving.
Create a Django project and application in a Python virtual environment and start the server
A complete guidebook to using pyenv, pip and python in an offline environment
Create a Vim + Python test environment in 1 minute
Create a GIF file using Pillow in Python
Create a virtual environment with conda in Python
Create a web map using Python and GDAL
Create a Mac app using py2app and Python3! !!
Create a MIDI file in Python using pretty_midi
Create a Python execution environment on IBM i
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Causes and solutions when python sam build fails in a newly created Cloud9 environment