|
| 1 | +from tkinter import * |
| 2 | +import tkinter as tk |
| 3 | +from tkinter.font import Font |
| 4 | +from tkinter import messagebox |
| 5 | +from tkinter import filedialog |
| 6 | +from thirdai import licensing, neural_db as ndb |
| 7 | + |
| 8 | +licensing.activate("1FB7DD-CAC3EC-832A67-84208D-C4E39E-V3") |
| 9 | +db = ndb.NeuralDB(user_id="my_user") |
| 10 | + |
| 11 | +root = Tk() |
| 12 | +root.geometry("600x500") |
| 13 | +root.title('ThirdAI - T&C') |
| 14 | + |
| 15 | +path = [] |
| 16 | + |
| 17 | + |
| 18 | +def customsize(sizeup): |
| 19 | + return Font(size=sizeup) |
| 20 | + |
| 21 | + |
| 22 | +def clear_all(): |
| 23 | + query_entry.delete(0, tk.END) |
| 24 | + text_box.delete(1.0, tk.END) |
| 25 | + path.clear() |
| 26 | + |
| 27 | + |
| 28 | +def training(): |
| 29 | + insertable_docs = [] |
| 30 | + value = path[0] |
| 31 | + pdf_files = value |
| 32 | + |
| 33 | + pdf_doc = ndb.PDF(value) |
| 34 | + insertable_docs.append(pdf_doc) |
| 35 | + |
| 36 | + print(insertable_docs) |
| 37 | + |
| 38 | + source_ids = db.insert(insertable_docs, train=True) |
| 39 | + |
| 40 | + def show_training_done_message(): |
| 41 | + messagebox.showinfo("Training Complete", "Training is done!") |
| 42 | + |
| 43 | + show_training_done_message() |
| 44 | + |
| 45 | + |
| 46 | +def processing(): |
| 47 | + question = query_entry.get() |
| 48 | + search_results = db.search( |
| 49 | + query=question, |
| 50 | + top_k=2, |
| 51 | + on_error=lambda error_msg: print(f"Error! {error_msg}")) |
| 52 | + |
| 53 | + output = "" |
| 54 | + for result in search_results: |
| 55 | + output += result.text + "\n" |
| 56 | + |
| 57 | + def process_data(output_data): |
| 58 | + output_window = tk.Toplevel(root) |
| 59 | + output_window.title("Output Data") |
| 60 | + output_window.geometry("500x500") |
| 61 | + |
| 62 | + output_text = tk.Text(output_window, wrap=tk.WORD, width=50, height=50) |
| 63 | + output_text.pack(padx=10, pady=10) |
| 64 | + output_text.insert(tk.END, output_data) |
| 65 | + |
| 66 | + process_data(output) |
| 67 | + |
| 68 | + |
| 69 | +def fileinput(): |
| 70 | + global path |
| 71 | + win = Tk() |
| 72 | + win.withdraw() |
| 73 | + file_type = dict(defaultextension=".pdf", filetypes=[("pdf file", "*.pdf")]) |
| 74 | + file_path = filedialog.askopenfilename(**file_type) |
| 75 | + print(file_path) |
| 76 | + file = file_path.split("/") |
| 77 | + print(file[-1]) |
| 78 | + path.append(file[-1]) |
| 79 | + print(path) |
| 80 | + text_box.insert(INSERT, file[-1]) |
| 81 | + |
| 82 | + |
| 83 | +menu = Label(root, text="Terms & Conditions", font=customsize(30), fg='black', highlightthickness=2, |
| 84 | + highlightbackground="red") |
| 85 | +menu.place(x=125, y=10) |
| 86 | + |
| 87 | +insert_button = Button(root, text="Insert File!", font=15, fg='black', bg="grey", width=10, command=fileinput) |
| 88 | +insert_button.place(x=245, y=100) |
| 89 | + |
| 90 | +text_box = tk.Text(root, wrap=tk.WORD, width=30, height=1) |
| 91 | +text_box.place(x=165, y=150) |
| 92 | + |
| 93 | +training = Button(root, text="Training", font=15, fg='black', bg="grey", width=10, command=training) |
| 94 | +training.place(x=245, y=195) |
| 95 | + |
| 96 | +query = Label(root, text="Query", font=customsize(20), fg='black') |
| 97 | +query.place(x=255, y=255) |
| 98 | + |
| 99 | +query_entry = tk.Entry(root, font=customsize(20), width=30) |
| 100 | +query_entry.place(x=70, y=300) |
| 101 | + |
| 102 | +processing = Button(root, text="Processing", font=15, fg='black', bg="grey", width=10, command=processing) |
| 103 | +processing.place(x=245, y=355) |
| 104 | + |
| 105 | +clear = Button(root, text="Clear", font=15, fg='black', bg="grey", width=10, command=clear_all) |
| 106 | +clear.place(x=245, y=405) |
| 107 | + |
| 108 | +root.mainloop() |
0 commit comments