code: # Copyright 2017 Bo Shao. All Rights Reserved.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  # ==============================================================================
  from __future__ import print_function
  
  import os
  import sys
  import tensorflow as tf
  
  from settings import PROJECT_ROOT
  from chatbot.botpredictor import BotPredictor
  
  
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
  
  
  def bot_ui():
      corp_dir = os.path.join(PROJECT_ROOT, 'Data', 'Corpus')
      knbs_dir = os.path.join(PROJECT_ROOT, 'Data', 'KnowledgeBase')
      res_dir = os.path.join(PROJECT_ROOT, 'Data', 'Result')
  
      with tf.Session() as sess:
          predictor = BotPredictor(sess, corpus_dir=corp_dir, knbase_dir=knbs_dir,
                                   result_dir=res_dir, result_file='basic')
          # This command UI has a single chat session only
          session_id = predictor.session_data.add_session()
  
          print("Welcome to Chat with ChatLearner!")
          print("Type exit and press enter to end the conversation.")
          # Waiting from standard input.
          sys.stdout.write("> ")
          sys.stdout.flush()
          question = sys.stdin.readline()
          while question:
              if question.strip() == 'exit':
                  print("Thank you for using ChatLearner. Goodbye.")
                  break
  
              print(predictor.predict(session_id, question))
              print("> ", end="")
              sys.stdout.flush()
              question = sys.stdin.readline()
  
  if __name__ == "__main__":
      bot_ui()
  
apis: tensorflow.Session