├── .github └── workflows │ └── codacy-analysis.yml ├── README.md ├── SECURITY.md ├── chat.txt ├── main.py └── requirements.txt /.github/workflows/codacy-analysis.yml: -------------------------------------------------------------------------------- 1 | # This workflow checks out code, performs a Codacy security scan 2 | # and integrates the results with the 3 | # GitHub Advanced Security code scanning feature. For more information on 4 | # the Codacy security scan action usage and parameters, see 5 | # https://github.com/codacy/codacy-analysis-cli-action. 6 | # For more information on Codacy Analysis CLI in general, see 7 | # https://github.com/codacy/codacy-analysis-cli. 8 | 9 | name: Codacy Security Scan 10 | 11 | on: 12 | push: 13 | branches: [ main ] 14 | pull_request: 15 | # The branches below must be a subset of the branches above 16 | branches: [ main ] 17 | schedule: 18 | - cron: '15 1 * * 4' 19 | 20 | jobs: 21 | codacy-security-scan: 22 | name: Codacy Security Scan 23 | runs-on: ubuntu-latest 24 | steps: 25 | # Checkout the repository to the GitHub Actions runner 26 | - name: Checkout code 27 | uses: actions/checkout@v2 28 | 29 | # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis 30 | - name: Run Codacy Analysis CLI 31 | uses: codacy/codacy-analysis-cli-action@1.1.0 32 | with: 33 | # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository 34 | # You can also omit the token and run the tools that support default configurations 35 | project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} 36 | verbose: true 37 | output: results.sarif 38 | format: sarif 39 | # Adjust severity of non-security issues 40 | gh-code-scanning-compat: true 41 | # Force 0 exit code to allow SARIF file generation 42 | # This will handover control about PR rejection to the GitHub side 43 | max-allowed-issues: 2147483647 44 | 45 | # Upload the SARIF file generated in the previous step 46 | - name: Upload SARIF results file 47 | uses: github/codeql-action/upload-sarif@v1 48 | with: 49 | sarif_file: results.sarif 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI-chatbot-GUI-using-tkinter 2 | ##### AI chatbot with GUI using Python Tkinter. This chat bot uses NLP(Natural language Prossesing) and takes Article as input and responds to user commands based on that Article. 3 | ##### In order to clone it and use it you have to follow some instructions listed below. 4 | 1. Inorder to run this you need to import all the libraries specified in 'requirements.txt' file. 5 | 6 | $ pip install -r requirements.txt 7 | 8 | Above command installs all the required libraries to run the project. 9 | 2. This application uses NLP and reads the Article you provide and give responses that are relavent to users query. 10 | 3. As some of the queries might not be understandable by chatbot but consider that it only provides based on that Article. 11 | 4. Defaultly we give Article based on Machine Learning but you can change the topic whatever you want by replacing Article link by your custom Article link(line 16 main.py). 12 | 5. After changes use ide such as 'Pycharm' for better visualization and interface.This is completely optional. 13 | ##### You can also see the sample output in 'chat.txt' file. 14 | ##### Thats it you are ready to use your chat bot ! 15 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /chat.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinadhreddy1184/AI-chatbot-GUI-using-tkinter/d6275bcdf8c95d1171f60b80cd370918da0f16ec/chat.txt -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | import os 4 | from tkinter import filedialog 5 | from newspaper import Article 6 | import random 7 | #import string 8 | FORMAT = "utf-8" 9 | import nltk 10 | from sklearn.feature_extraction.text import CountVectorizer 11 | from sklearn.metrics.pairwise import cosine_similarity 12 | import warnings 13 | warnings.filterwarnings('ignore') 14 | text_contents=dict() 15 | nltk.download('punkt',quiet=True) 16 | arc=Article('https://developer.ibm.com/languages/python/articles/introduction-to-machine-learning/') 17 | arc.download() 18 | arc.parse() 19 | arc.nlp() 20 | corpus=arc.text 21 | #tokenisation 22 | text=corpus 23 | sentencelist=nltk.sent_tokenize(text)#list of sentences 24 | 25 | def greet_res(text): 26 | text=text.lower() 27 | bot_greet=['hi','hello','hola','hey','howdy'] 28 | usr_greet=['hi','hey','hello','hola','greetings','wassup','whats up'] 29 | for word in text.split(): 30 | if word in usr_greet: 31 | return random.choice(bot_greet) 32 | 33 | def index_sort(list_var): 34 | length=len(list_var) 35 | list_index=list(range(0,length)) 36 | x=list_var 37 | for i in range(length): 38 | for j in range(length): 39 | if x[list_index[i]] > x[list_index[j]]: 40 | temp=list_index[i] 41 | list_index[i]=list_index[j] 42 | list_index[j]=temp 43 | return list_index 44 | # bot response 45 | def bot_ress(usr_input): 46 | usr_input = usr_input.lower() 47 | sentencelist.append(usr_input) 48 | bot_res = '' 49 | cm = CountVectorizer().fit_transform(sentencelist) 50 | similarity_scores = cosine_similarity(cm[-1], cm) 51 | similarity_scores_list = similarity_scores.flatten() 52 | index = index_sort(similarity_scores_list) 53 | index = index[1:] 54 | response_flag = 0 55 | j = 0 56 | for i in range(len(index)): 57 | if similarity_scores_list[index[i]] > 0.0: 58 | bot_res = bot_res + ' ' + sentencelist[index[i]] 59 | response_flag = 1 60 | j = j + 1 61 | if j > 2: 62 | break 63 | if response_flag == 0: 64 | bot_res = bot_res + ' ' + 'I am sorry, I don\'t understand.' 65 | 66 | sentencelist.remove(usr_input) 67 | return bot_res 68 | def widget_get(): 69 | text_widget = root.nametowidget(textcon) 70 | return text_widget.get('1.0','end-1c') 71 | 72 | def saveas(event=None): 73 | global file_path,filename 74 | file_path= filedialog.asksaveasfilename( defaultextension=".txt") 75 | try: 76 | filename=os.path.basename(file_path) 77 | root.title(f"Chat Bot - {filename}") 78 | content=widget_get() 79 | with open(file_path ,"w") as file: 80 | file.write(content) 81 | text_contents[str(textcon)]=hash(content) 82 | print("Operation successfull") 83 | except(FileNotFoundError): 84 | print("Operation not successfull") 85 | return None 86 | file_path =None 87 | 88 | def save(event=None): 89 | global file_path,filename 90 | try: 91 | if(file_path is None): 92 | file_path = filedialog.asksaveasfilename(defaultextension=".txt") 93 | filename=os.path.basename(file_path) 94 | root.title(f"Chat Bot - {filename}") 95 | content=widget_get() 96 | with open(file_path ,"w") as file: 97 | file.write(content) 98 | text_contents[str(textcon)] = hash(content) 99 | print("Operation successfull") 100 | except(FileNotFoundError): 101 | print("Operation not successfull") 102 | return None 103 | 104 | def new(event=None): 105 | textcon.delete('2.0', 'end-1c') 106 | global file_path,filename 107 | file_path = None 108 | content = widget_get() 109 | text_contents[str(textcon)] = hash(content) 110 | filename=None 111 | 112 | """def check_changes(event=None): 113 | global filename 114 | current=widget_get() 115 | content=current.get() 116 | name =filename 117 | if hash(current)!=text_contents[str(textcon)]: 118 | if name[-1]!="*": 119 | filename=name+"*" 120 | 121 | elif name[-1]=="*": 122 | filename=name 123 | root.title(f"Chat Bot - {filename}") 124 | """ 125 | 126 | 127 | def clear(event=None): 128 | textcon.delete('2.0', 'end-1c') 129 | content = widget_get() 130 | text_contents[str(textcon)] = hash(content) 131 | def fopen(event=None): 132 | global file_path,filename 133 | file_path = filedialog.askopenfilename(defaultextension=".txt") 134 | try: 135 | filename = os.path.basename(file_path) 136 | root.title(f"Chat Bot - {filename}") 137 | text_widget = root.nametowidget(textcon) 138 | with open(file_path, "r") as file: 139 | content=file.read() 140 | textcon.delete('1.0', 'end-1c') 141 | text_contents[str(textcon)] = hash(content) 142 | text_widget.insert(END,content) 143 | print("Operation successfull") 144 | except(FileNotFoundError): 145 | print("Operation not successfull") 146 | return None 147 | 148 | 149 | 150 | exit_list = ['exit','break','quit','see you later','chat with you later','end the chat','bye','ok bye'] 151 | 152 | 153 | 154 | def send(event=None): 155 | usr_input = message.get() 156 | usr_input = usr_input.lower() 157 | textcon.insert(END, f'User: {usr_input}'+'\n','usr') 158 | if usr_input in exit_list: 159 | textcon.config(fg='yellow') 160 | textcon.insert(END,"Bot:Ok bye! Chat with you later\n") 161 | return root.destroy() 162 | else: 163 | textcon.config(fg='yellow') 164 | if greet_res(usr_input) != None: 165 | lab=f"Bot: {greet_res(usr_input)}"+'\n' 166 | textcon.insert(END,lab) 167 | else: 168 | lab = f"Bot: {bot_ress(usr_input)}"+'\n' 169 | textcon.insert(END, lab) 170 | root=tk.Tk() 171 | filename="Untitled.txt" 172 | root.title(f"Chat Bot - Untitled.txt") 173 | root.geometry('500x400') 174 | 175 | root.resizable(False, False) 176 | main_menu=Menu(root) 177 | file_menu=Menu(root) 178 | file_menu.add_command(label='Open ',command=fopen) 179 | file_menu.add_command(label='New ',command=new) 180 | file_menu.add_command(label='Save ',command=save) 181 | file_menu.add_command(label='Save as ',command=saveas) 182 | edit_menu=Menu(root) 183 | edit_menu.add_command(label='Clear ',command=clear) 184 | edit_menu.add_command(label='Preferences') 185 | main_menu.add_cascade(label="File",menu=file_menu) 186 | main_menu.add_cascade(label="Edit",menu=edit_menu) 187 | main_menu.add_command(label="Quit",command=root.destroy) 188 | root.config(menu=main_menu) 189 | message=tk.StringVar() 190 | chat_win=Frame(root,bd=1,bg='black',width=50,height=8) 191 | chat_win.place(x=6,y=6,height=300,width=480) 192 | textcon=tk.Text(chat_win,bd=1,bg='black',width=50,height=8) 193 | textcon.pack(fill="both",expand=True) 194 | mes_win=Entry(root,width=30,xscrollcommand=True,textvariable=message) 195 | mes_win.place(x=6,y=310,height=60,width=366) 196 | mes_win.focus() 197 | textcon.config(fg='yellow') 198 | textcon.tag_config('usr',foreground='white') 199 | textcon.insert(END,"Bot: This is your chat bot to assist you about Machine Learning!\n\n") 200 | mssg=mes_win.get() 201 | button=Button(root,text='Send',bg='yellow',activebackground='orange',command=send,width=12,height=5,font=('Arial')) 202 | button.place(x=376,y=310,height=60,width=110) 203 | scrollbar=tk.Scrollbar(textcon) 204 | scrollbar.pack(fill='y') 205 | scrollbar.place(relheight = 1,relx = 1) 206 | scrollbar.config(command = textcon.yview) 207 | content = widget_get() 208 | text_contents[str(textcon)] = hash(content) 209 | root.bind('',save,file_menu) 210 | root.bind('',saveas,file_menu) 211 | root.bind('', send,button) 212 | root.bind('', new,file_menu) 213 | root.bind('', clear,edit_menu) 214 | root.bind('', fopen,file_menu) 215 | root.mainloop() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.9.3 2 | certifi==2020.12.5 3 | chardet==4.0.0 4 | click==7.1.2 5 | cssselect==1.1.0 6 | feedfinder2==0.0.4 7 | feedparser==6.0.2 8 | filelock==3.0.12 9 | idna==2.10 10 | jieba3k==0.35.1 11 | joblib==1.0.1 12 | lxml==4.6.3 13 | newspaper3k==0.2.8 14 | nltk==3.6.2 15 | numpy==1.20.2 16 | Pillow==8.2.0 17 | python-dateutil==2.8.1 18 | PyYAML==5.4.1 19 | regex==2021.4.4 20 | requests==2.25.1 21 | requests-file==1.5.1 22 | scikit-learn==0.24.2 23 | scipy==1.6.3 24 | sgmllib3k==1.0.0 25 | six==1.16.0 26 | soupsieve==2.2.1 27 | threadpoolctl==2.1.0 28 | tinysegmenter==0.3 29 | tldextract==3.1.0 30 | tqdm==4.60.0 31 | urllib3==1.26.4 32 | --------------------------------------------------------------------------------