def __init__(self): self.frame = Frame() self.condition = Condition() self.port = 8080 self.connected = False self.sample = "" self.max_sockets = 1024 self.stream_id = b'12345' self.threads = []
def make_frame(self, code, callargs={}, global_names=None, local_names=None): """ make frame :rtype: object """ if global_names is not None and local_names is not None: local_names = global_names elif self.frames: global_names = self.current_frame.global_names local_names = {} else: global_names = local_names = { '__builtins__': __builtins__, '__name__': '__main__', '__doc__': None, '__package__': None, } local_names.update(callargs) frame = Frame(code, global_names, local_names, self.current_frame) return frame
def __init__(self): super().__init__() self.setMenuBar(QMenuBar()) self.deploy_files_action = QAction(QIcon('resources/deploy.png'), "Deploy selected", self) self.backup_files_action = QAction(QIcon('resources/backup.png'), "Backup selected", self) self.settings_action = QAction(QIcon('resources/settings.png'), "Settings", self) self.exit_action = QAction(QIcon('resources/exit.png'), "Exit", self) self.deploy_files_action.connect(self.deploy_files_action, SIGNAL("triggered()"), self.deploy_files) self.backup_files_action.connect(self.backup_files_action, SIGNAL("triggered()"), self.backup_files) self.settings_action.connect(self.settings_action, SIGNAL("triggered()"), self.show_settings) self.exit_action.connect(self.exit_action, SIGNAL("triggered()"), self.exit) self.file_menu = self.menuBar().addMenu("File") self.file_menu.addAction(self.settings_action) self.file_menu.addAction(self.exit_action) self.actions_menu = self.menuBar().addMenu("Actions") self.actions_menu.addAction(self.backup_files_action) self.actions_menu.addAction(self.deploy_files_action) """ ################################################## """ # outer frame. this is the central widget for the application self.outer_frame = Frame(QVBoxLayout(), QFrame.StyledPanel) # inner top frame. holds list widget and tab widget self.inner_top_frame = Frame(QHBoxLayout(), QFrame.StyledPanel) # inner btm frame. self.inner_btm_frame = Frame(QVBoxLayout(), QFrame.StyledPanel) # text area self.display_area = TextDisplay() # status bar. shows hover actions and status self.status_bar = QStatusBar() self.setStatusBar(self.status_bar) self.status_bar.showMessage("Status Bar Message...") # tab widget. holds description and powershell tabs. they both have text boxes inside to display text self.tab_container = TabContainer() tabs = (Tab("Description", TextDisplay(), QVBoxLayout()), Tab("Powershell", TextDisplay(), QVBoxLayout())) self.tab_container.set_tabs(tabs) # list widget. holds selectable items self.list_widget = ListWidget() self.list_items = [ListItem("PXSurveyAPI"), ListItem("PXWeb"), ListItem("PXReporting"), ListItem("PXNotification"), ListItem("SampleUI"), ListItem("SampleEngine"), ListItem("PXClientMGMT"), ListItem("InsightsOnline"), ListItem("TEST"), ListItem("PXSurveyMGMT"), ListItem("PXVerintSurveyACL")] self.list_widget.add_sort_list_items(self.list_items) self.list_widget.connect(self.list_widget, SIGNAL("itemClicked(QListWidgetItem*)"), self.selected) # pull everything together. self.inner_top_frame.get_layout().addWidget(self.list_widget) self.inner_btm_frame.get_layout().addWidget(self.tab_container) self.outer_frame.get_layout().addWidget(self.inner_top_frame) self.outer_frame.get_layout().addWidget(self.inner_btm_frame) self.inner_top_frame.get_layout().addWidget(self.display_area) self.setWindowIcon(QIcon('resources\conan.png')) self.setCentralWidget(self.outer_frame) self.show() """
class Window(QMainWindow): def __init__(self): super().__init__() self.setMenuBar(QMenuBar()) self.deploy_files_action = QAction(QIcon('resources/deploy.png'), "Deploy selected", self) self.backup_files_action = QAction(QIcon('resources/backup.png'), "Backup selected", self) self.settings_action = QAction(QIcon('resources/settings.png'), "Settings", self) self.exit_action = QAction(QIcon('resources/exit.png'), "Exit", self) self.deploy_files_action.connect(self.deploy_files_action, SIGNAL("triggered()"), self.deploy_files) self.backup_files_action.connect(self.backup_files_action, SIGNAL("triggered()"), self.backup_files) self.settings_action.connect(self.settings_action, SIGNAL("triggered()"), self.show_settings) self.exit_action.connect(self.exit_action, SIGNAL("triggered()"), self.exit) self.file_menu = self.menuBar().addMenu("File") self.file_menu.addAction(self.settings_action) self.file_menu.addAction(self.exit_action) self.actions_menu = self.menuBar().addMenu("Actions") self.actions_menu.addAction(self.backup_files_action) self.actions_menu.addAction(self.deploy_files_action) """ ################################################## """ # outer frame. this is the central widget for the application self.outer_frame = Frame(QVBoxLayout(), QFrame.StyledPanel) # inner top frame. holds list widget and tab widget self.inner_top_frame = Frame(QHBoxLayout(), QFrame.StyledPanel) # inner btm frame. self.inner_btm_frame = Frame(QVBoxLayout(), QFrame.StyledPanel) # text area self.display_area = TextDisplay() # status bar. shows hover actions and status self.status_bar = QStatusBar() self.setStatusBar(self.status_bar) self.status_bar.showMessage("Status Bar Message...") # tab widget. holds description and powershell tabs. they both have text boxes inside to display text self.tab_container = TabContainer() tabs = (Tab("Description", TextDisplay(), QVBoxLayout()), Tab("Powershell", TextDisplay(), QVBoxLayout())) self.tab_container.set_tabs(tabs) # list widget. holds selectable items self.list_widget = ListWidget() self.list_items = [ListItem("PXSurveyAPI"), ListItem("PXWeb"), ListItem("PXReporting"), ListItem("PXNotification"), ListItem("SampleUI"), ListItem("SampleEngine"), ListItem("PXClientMGMT"), ListItem("InsightsOnline"), ListItem("TEST"), ListItem("PXSurveyMGMT"), ListItem("PXVerintSurveyACL")] self.list_widget.add_sort_list_items(self.list_items) self.list_widget.connect(self.list_widget, SIGNAL("itemClicked(QListWidgetItem*)"), self.selected) # pull everything together. self.inner_top_frame.get_layout().addWidget(self.list_widget) self.inner_btm_frame.get_layout().addWidget(self.tab_container) self.outer_frame.get_layout().addWidget(self.inner_top_frame) self.outer_frame.get_layout().addWidget(self.inner_btm_frame) self.inner_top_frame.get_layout().addWidget(self.display_area) self.setWindowIcon(QIcon('resources\conan.png')) self.setCentralWidget(self.outer_frame) self.show() """ Call powershell function and pass parameters: script_path = "c:\\users\\cherbison\\desktop\\test-function.ps1" posh_path = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" posh2 = subprocess.call([posh_path, ". \"" + script_path + "\";", "&test-function(\" test \")"]) script call def call_script(self, type_, btn_pushed): posh = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" script = self.script_path + type_ + "_" + btn_pushed + ".ps1" try: subprocess.Popen([posh, "Start-Process", '-Verb', "runAs", posh, [script]]) except subprocess.CalledProcessError as e: print(e.output, "There was an error.") @staticmethod def read_file(file_path): file = open(file_path) return file.read() """ def deploy_files(self): self.display_area.append("deploy files clicked") def backup_files(self): self.display_area.append("backup files clicked") def show_settings(self): self.display_area.append("settings clicked") def selected(self): selected_item = self.list_widget.currentItem().text self.display_area.append(selected_item + " selected") self.display_area.ensureCursorVisible() def exit(self): self.display_area.append("exit clicked")
def __init__(self): # create default personalities cm = Character_Manager() cm.save("character_default") cm.save("character_stable") cm.save("character_empathetic") cm.save("character_irascible") # set up logging logging.basicConfig( level=logging.INFO, filename='../logs/app.log', filemode="w", format='%(asctime)s %(name)s/%(levelname)s - - %(message)s', datefmt='%d.%m.%y %H:%M:%S') self.logger = logging.getLogger("controller") self.logger.setLevel(logging.INFO) # read config file and save values in variables self.config = configparser.ConfigParser() self.config.read("../config/config.ini") self.botname = self.config.get("default", "botname") self.username = self.config.get("default", "username") self.classifier_data = [ self.config.get("net", "classifier_type"), self.config.get("net", "dataset"), self.config.get("net", "feature_set") ] self.logger.info("Conifg loaded: {}, {}, {}".format( self.botname, self.username, self.classifier_data)) # initialize emotional variables self.lex_happiness = pd.read_csv("../lexica/clean_happiness.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_sadness = pd.read_csv("../lexica/clean_sadness.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_anger = pd.read_csv("../lexica/clean_anger.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_fear = pd.read_csv("../lexica/clean_fear.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.LIST_OF_LEXICA = self.lex_happiness, self.lex_sadness, self.lex_anger, self.lex_fear self.list_happiness = self.lex_happiness["stems"].tolist() self.list_sadness = self.lex_sadness["stems"].tolist() self.list_anger = pd.Series(self.lex_anger["stems"].tolist()) self.list_fear = self.lex_fear["stems"].tolist() self.lex_happiness_adj = pd.read_csv( "../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_sadness_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_anger_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_fear_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.logger.info("Lexica loaded") # initialize ml-variables if self.config.getboolean("default", "firstlaunch"): # das md-model ist ca 80mb, das lg ca 1g # self.nlp = spacy.load("en_core_web_lg") self.nlp = spacy.load("en_core_web_md") else: self.nlp = spacy.load("../models/spacy") self.spell = SpellChecker() # create bot, responsible for generating answers and classifier, for analysing the input self.character = Character( self.config.getboolean("default", "firstlaunch")) self.classifier = Classifier(self.classifier_data, self.LIST_OF_LEXICA, self.nlp) self.bot = Bot(self.lex_happiness, self.lex_sadness, self.lex_anger, self.lex_fear, self.list_happiness, self.list_sadness, self.list_anger, self.list_fear, self.lex_happiness_adj, self.lex_sadness_adj, self.lex_anger_adj, self.lex_fear_adj, self.nlp) if self.config.getboolean("default", "firstlaunch"): self.bot.train() # create frame and update widgets with initial values self.frame = Frame(self.botname, self.character.get_emotional_state(), self.character.get_emotional_history()) self.frame.register_subscriber(self) self.frame.show() # save all session data after the frame is closed self.save_session() logging.shutdown()
class Controller: def __init__(self): # create default personalities cm = Character_Manager() cm.save("character_default") cm.save("character_stable") cm.save("character_empathetic") cm.save("character_irascible") # set up logging logging.basicConfig( level=logging.INFO, filename='../logs/app.log', filemode="w", format='%(asctime)s %(name)s/%(levelname)s - - %(message)s', datefmt='%d.%m.%y %H:%M:%S') self.logger = logging.getLogger("controller") self.logger.setLevel(logging.INFO) # read config file and save values in variables self.config = configparser.ConfigParser() self.config.read("../config/config.ini") self.botname = self.config.get("default", "botname") self.username = self.config.get("default", "username") self.classifier_data = [ self.config.get("net", "classifier_type"), self.config.get("net", "dataset"), self.config.get("net", "feature_set") ] self.logger.info("Conifg loaded: {}, {}, {}".format( self.botname, self.username, self.classifier_data)) # initialize emotional variables self.lex_happiness = pd.read_csv("../lexica/clean_happiness.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_sadness = pd.read_csv("../lexica/clean_sadness.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_anger = pd.read_csv("../lexica/clean_anger.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.lex_fear = pd.read_csv("../lexica/clean_fear.csv", delimiter=",", dtype={ "text": str, "affect": str, "stems": str }, float_precision='round_trip') self.LIST_OF_LEXICA = self.lex_happiness, self.lex_sadness, self.lex_anger, self.lex_fear self.list_happiness = self.lex_happiness["stems"].tolist() self.list_sadness = self.lex_sadness["stems"].tolist() self.list_anger = pd.Series(self.lex_anger["stems"].tolist()) self.list_fear = self.lex_fear["stems"].tolist() self.lex_happiness_adj = pd.read_csv( "../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_sadness_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_anger_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.lex_fear_adj = pd.read_csv("../lexica/clean_happiness_adj.csv", delimiter=",", dtype={ "text": str, "intensity": float }, float_precision='round_trip') self.logger.info("Lexica loaded") # initialize ml-variables if self.config.getboolean("default", "firstlaunch"): # das md-model ist ca 80mb, das lg ca 1g # self.nlp = spacy.load("en_core_web_lg") self.nlp = spacy.load("en_core_web_md") else: self.nlp = spacy.load("../models/spacy") self.spell = SpellChecker() # create bot, responsible for generating answers and classifier, for analysing the input self.character = Character( self.config.getboolean("default", "firstlaunch")) self.classifier = Classifier(self.classifier_data, self.LIST_OF_LEXICA, self.nlp) self.bot = Bot(self.lex_happiness, self.lex_sadness, self.lex_anger, self.lex_fear, self.list_happiness, self.list_sadness, self.list_anger, self.list_fear, self.lex_happiness_adj, self.lex_sadness_adj, self.lex_anger_adj, self.lex_fear_adj, self.nlp) if self.config.getboolean("default", "firstlaunch"): self.bot.train() # create frame and update widgets with initial values self.frame = Frame(self.botname, self.character.get_emotional_state(), self.character.get_emotional_history()) self.frame.register_subscriber(self) self.frame.show() # save all session data after the frame is closed self.save_session() logging.shutdown() # takes the users intent (per gui interaction) and starts the corresponding methods def handle_intent(self, intent, input_message=None, character=None, classifier_type=None, dataset=None, feature_set=None): if intent == "load_character": self.character.load(character) self.frame.update_diagrams(self.character.get_emotional_state(), self.character.get_emotional_history()) self.frame.update_log( [{ "character ready": self.character.character_name }], clear=True) elif intent == "get_response": if input_message and input_message != "": self.handle_input(input_message) elif intent == "retrain_bot": self.bot.train() self.frame.update_log(["chatbot training completed"], clear=True) elif intent == "reset_state": self.character.reset_bot() self.frame.update_diagrams(self.character.get_emotional_state(), self.character.get_emotional_history()) self.frame.update_log(["chatbot internal state reset"], clear=True) elif intent == "change_classifier": self.classifier_data = [classifier_type, dataset, feature_set] self.classifier.load_network(self.classifier_data) self.frame.update_log([{ "classifier ready": self.classifier_data }], clear=True) self.logger.info("classifier loaded: {}".format(" ".join( self.classifier_data))) # take user input, generate new data an update ui def handle_input(self, user_input): # user_input = self.correct_input(user_input) # update all modules response_package = self.bot.respond(user_input) ml_package = self.classifier.get_emotions(user_input) state_package = self.character.update_emotional_state( ml_package.get("input_emotions")) response_package = self.bot.modify_output( response_package, state_package["highest_emotion"], state_package["highest_score"]) # update gui self.frame.update_chat_out(user_input, response_package.get("response").__str__(), self.botname, self.username) self.frame.update_log([{ "classifier": " ".join(self.classifier_data), "character": self.character.character_name }, ml_package, state_package]) self.frame.update_diagrams(state_package.get("emotional_state"), state_package.get("emotional_history")) # corrects user input def correct_input(self, user_input): # make list of all words words = user_input.split(" ") unknown_words = self.spell.unknown(words) # replace all unknown words for word in unknown_words: print("correction: ", word, self.spell.correction(word)) user_input = user_input.replace(word, self.spell.correction(word)) return user_input # handles saving data when closing the program def save_session(self): # saves current character state self.character.save() # set the first launch variable to false self.config.set("default", "firstlaunch", "NO") self.config.set("net", "classifier_type", self.classifier_data[0]) self.config.set("net", "dataset", self.classifier_data[1]) self.config.set("net", "feature_set", self.classifier_data[2]) # save nlp model print("saving spacy") self.nlp.to_disk("../models/spacy") # save new value in file with open("../config/config.ini", "w") as f: self.config.write(f) self.logger.info(f"Session saved - end program")