import numpy as np
import os
import sys
import tensorflow as tf

from settings import PROJECT_ROOT
from chatbot.tokenizeddata import TokenizedData
from chatbot.botpredictor import BotPredictor

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

def bot_ui():
    dict_file = os.path.join(PROJECT_ROOT, 'Data', 'Result', 'dicts.pickle')
    td = TokenizedData(seq_length=10, dict_file=dict_file)

    res_dir = os.path.join(PROJECT_ROOT, 'Data', 'Result')
    with tf.Session() as sess:
        predictor = BotPredictor(sess, td, res_dir, 'basic')

        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()
        sentence = sys.stdin.readline()
        while sentence:
            if sentence.strip() == 'exit':
                print("Thank you for using ChatLearner. Bye.")
                break

            dec_outputs = predictor.predict(sentence)

            word_ids = []
            for out in dec_outputs:
                word_ids.append(np.argmax(out))

            print(td.word_ids_to_str(word_ids))
            print("> ", end="")
            sys.stdout.flush()
            sentence = sys.stdin.readline()

if __name__ == "__main__":
    bot_ui()

import numpy as np
import os
import sys
import tensorflow as tf

from settings import PROJECT_ROOT
from chatbot.tokenizeddata import TokenizedData
from chatbot.botpredictor import BotPredictor


def bot_ui():
    data_file = os.path.join(PROJECT_ROOT, 'Data', 'Corpus', 'basic_conv.txt')
    td = TokenizedData(seq_length=10, data_file=data_file)

    res_dir = os.path.join(PROJECT_ROOT, 'Data', 'Result')
    with tf.Session() as sess:
        predictor = BotPredictor(sess, td, res_dir, 'basic')

        # Waiting from standard input.
        sys.stdout.write("> ")
        sys.stdout.flush()
        sentence = sys.stdin.readline()
        while sentence:
            dec_outputs = predictor.predict(sentence)

            word_ids = []
            for out in dec_outputs:
                word_ids.append(np.argmax(out))

            print(td.word_ids_to_str(word_ids))
            print("> ", end="")
            sys.stdout.flush()
            sentence = sys.stdin.readline()

if __name__ == "__main__":
    bot_ui()

--- 
+++ 
@@ -7,20 +7,27 @@
 from chatbot.tokenizeddata import TokenizedData
 from chatbot.botpredictor import BotPredictor
 
+os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
 
 def bot_ui():
-    data_file = os.path.join(PROJECT_ROOT, 'Data', 'Corpus', 'basic_conv.txt')
-    td = TokenizedData(seq_length=10, data_file=data_file)
+    dict_file = os.path.join(PROJECT_ROOT, 'Data', 'Result', 'dicts.pickle')
+    td = TokenizedData(seq_length=10, dict_file=dict_file)
 
     res_dir = os.path.join(PROJECT_ROOT, 'Data', 'Result')
     with tf.Session() as sess:
         predictor = BotPredictor(sess, td, res_dir, 'basic')
 
+        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()
         sentence = sys.stdin.readline()
         while sentence:
+            if sentence.strip() == 'exit':
+                print("Thank you for using ChatLearner. Bye.")
+                break
+
             dec_outputs = predictor.predict(sentence)
 
             word_ids = []
Optimize the UI and allow the user to exit the program smoothly.
