text: import traceback
  
  from common import common
  from pharo_extractor import Extractor
  
  SHOW_TOP_CONTEXTS = 10
  MAX_PATH_LENGTH = 8
  MAX_PATH_WIDTH = 2
  PHARO_IMAGE_PATH = 'PharoExtractor/Pharo.image'
  INPUT_FILENAME = 'input.src'
  
  
  class InteractivePredictor:
      exit_keywords = ['exit', 'quit', 'q']
  
      def __init__(self, config, model):
          model.predict([])
          self.model = model
          self.config = config
          self.path_extractor = Extractor(config,
                                          pharo_image_path=PHARO_IMAGE_PATH,
                                          max_path_length=MAX_PATH_LENGTH,
                                          max_path_width=MAX_PATH_WIDTH)
  
      def read_file(self, input_filename):
          with open(input_filename, 'r') as file:
              return file.readlines()
  
      def predict(self):
          print('Starting interactive prediction...')
          while True:
              print(
                  'Modify the file: "%s" and press any key when ready, or "q" / "quit" / "exit" to exit' % INPUT_FILENAME)
              user_input = input()
              if user_input.lower() in self.exit_keywords:
                  print('Exiting...')
                  return
              try:
                  predict_lines, hash_to_string_dict = self.path_extractor.extract_paths(INPUT_FILENAME)
              except ValueError as e:
                  print(e)
                  continue
              results = self.model.predict(predict_lines)
              prediction_results = common.parse_results(results, hash_to_string_dict, topk=SHOW_TOP_CONTEXTS)
              for method_prediction in prediction_results:
                  print('Original name:\t' + method_prediction.original_name)
                  for name_prob_pair in method_prediction.predictions:
                      print('\t(%f) predicted: %s' % (name_prob_pair['probability'], name_prob_pair['name']))
                  print('Attention:')
                  for attention_obj in method_prediction.attention_paths:
                      print('%f\tcontext: %s,%s,%s' % (
                      attention_obj['score'], attention_obj['token1'], attention_obj['path'], attention_obj['token2']))
  