def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) # Set title and good inital window size tk.Tk.wm_title(self, "BakerAI") self.geometry("1000x700") # Container is parent frame, containing all frames parent = tk.Frame(self) parent.pack(side="top", fill="both", expand=True) # Format: min size, weight is z index parent.grid_rowconfigure(0, weight=1) parent.grid_columnconfigure(0, weight=1) # Main frame layout: where content is stored mainFrame = tk.Frame(parent) mainFrame.pack(side="top", fill="both", expand=True) for i in range(9): mainFrame.grid_rowconfigure(index=i, weight=1) mainFrame.grid_columnconfigure(index=i, weight=1) self.loaded_clf = m.load_sentiment_analysis()[0] # Elements of the main frame # # Title title = tk.Label(mainFrame, text="Welcome to Sakura's very own BakerAI!", font=TITLE_FONT) title.grid(row=1, column=1, columnspan=7) # What we will change to show output self.outputBox = tk.Text(mainFrame, font=FONT) self.outputBox.grid(row=3, column=1, columnspan=7, rowspan=1, sticky="") self.outputBox.insert(tk.END, "BakerAI: Hey there! How can I help you? \n") self.outputBox.configure(state="disabled") scrollbar = tk.Scrollbar(self) scrollbar.config(command=self.outputBox.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.outputBox.config(yscrollcommand=scrollbar.set) # Input related items entryLabel = tk.Label(mainFrame, text="Enter your text below!", font=FONT) entryLabel.grid(row=4, column=2, columnspan=2, sticky="") self.userInput = tk.Entry(mainFrame) self.userInput.grid(row=5, column=1, columnspan=4, sticky="EW") sendButton = tk.Button(mainFrame, text="Send message", command=lambda: self.getResponse()) sendButton.grid(row=5, column=6, columnspan=1, sticky="EW") print(target_tag) self.userInput.bind("<Return>", lambda x: self.getResponse())
def openCloseConnection(self, connectionInfo): self.sock.bind(connectionInfo) # Bind to an address to recive client responses self.sock.listen(1) # Get one clinet conn, addr, = self.sock.accept() loaded_clf = m.load_sentiment_analysis()[0] while(True): # While we still get valid responses from our 1 client clientResponse=self.getResponse(conn) if not clientResponse: # If the data we got is empty or terminating condition break print("Client message: " + clientResponse) response = m.getFinalOutput(loaded_clf, clientResponse) if clientResponse == "quit": response = "Goodbye!" self.sendResponse(response, conn) conn.close() print("We've lost our client")
def __init__(self): self.loaded_clf = m.load_sentiment_analysis()[0] # Take in basic paramaters with open(f'{pathlib.Path(__file__).parent.absolute()}\\intents.json' ) as jsonFile: self.data = json.load(jsonFile)
def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) # Set title and good inital window size tk.Tk.wm_title(self, "BakerAI") self.geometry("1000x700") # Container is parent frame, containing all frames parent = tk.Frame(self) parent.pack(side="top", fill="both", expand=True) # Format: min size, weight is z index parent.grid_rowconfigure(0, weight=1) parent.grid_columnconfigure(0, weight=1) # Main frame layout: where content is stored mainFrame = tk.Frame(parent) mainFrame.pack(side="top", fill="both", expand=True) for i in range(9): mainFrame.grid_rowconfigure(index=i, weight=1) mainFrame.grid_columnconfigure(index=i, weight=1) self.loaded_clf = m.load_sentiment_analysis()[0] # Create the language map self.languages = { "English": "en", "Français": "fr", "Русский": "ru", "Español": "es", "Suomi": "fi" } # Elements of the main frame # # Title label title = tk.Label(mainFrame, text="Welcome to Sakura's very own BakerAI!", font=TITLE_FONT) title.grid(row=1, column=1, columnspan=7) # Add labels for input entryLabel = tk.Label( mainFrame, text= "Enter your text below! Type 'Wiki <text>' to query Wikipedia.", font=FONT) entryLabel.grid(row=4, column=1, columnspan=4, sticky="") # What we will change to show output self.outputBox = tk.Text(mainFrame, font=FONT) self.outputBox.grid(row=3, column=1, columnspan=7, rowspan=1, sticky="") self.outputBox.insert(tk.END, "BakerAI: Hey there! How can I help you? \n") self.outputBox.configure(state="disabled") # Create a scrollbar and configure it scrollbar = tk.Scrollbar(self) scrollbar.config(command=self.outputBox.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.outputBox.config(yscrollcommand=scrollbar.set) # Input related items self.userInput = tk.Entry(mainFrame) self.userInput.grid(row=5, column=1, columnspan=4, sticky="EW") sendButton = tk.Button(mainFrame, text="Send message", command=lambda: self.getResponse()) sendButton.grid(row=5, column=6, columnspan=1, sticky="EW") self.userInput.bind("<Return>", lambda x: self.getResponse()) # Language selector optionList = list(self.languages.keys()) self.lan = tk.StringVar() self.lan.set(optionList[0]) # Set the current language to english self.lanSelection = tk.OptionMenu(mainFrame, self.lan, *optionList) self.lanSelection.grid(row=5, column=7, columnspan=1, sticky="EW")