diff --git a/Chatbot.py b/Chatbot.py new file mode 100644 index 0000000..af643a3 --- /dev/null +++ b/Chatbot.py @@ -0,0 +1,156 @@ +import io +import json +import random +import string +import sys +from sklearn.feature_extraction.text import TfidfVectorizer +from sklearn.metrics.pairwise import cosine_similarity +import sqlite3 +import warnings +warnings.filterwarnings('ignore') +from details import * +from template import * +import nltk +from PyQt5.QtWidgets import QApplication,QMainWindow,QDialog,QMessageBox,QAction +from PyQt5.QtGui import QFont, QIcon +from PyQt5.QtCore import QTime, QDate +from nltk.stem import WordNetLemmatizer +class gui(QMainWindow): + def __init__(self): + super().__init__() + self.setWindowTitle("Chatbot") + self.setWindowIcon(QIcon(r'roboimg.png')) + self.ui=Ui_MainWindow() + self.ui.setupUi(self) + self.operator=project() + reply=self.operator.database() + self.ui.plainTextEdit.setPlainText("Alis: Hello {}, My name is Alis. How can I help you".format(self.operator.name)) + if reply==False: + self.ui.plainTextEdit.appendPlainText("Alis: Sir if you want to save your details Go to File->Change Details") + self.ui.pushButton.clicked.connect(self.maintain) + font1=QFont() + font1.setPointSize(12) + action=QAction(self) + action.setShortcut("Return") + self.addAction(action) + action.triggered.connect(self.maintain) + self.ui.plainTextEdit.setFont(font1) + self.ui.lineEdit.setFocus() + self.ui.actionChange_details.triggered.connect(self.change) + self.show() + def maintain(self): + user_response = self.ui.lineEdit.text() + self.ui.plainTextEdit.appendPlainText("{}: ".format(self.operator.name)+user_response) + user_response = user_response.lower() + response=self.operator.greeting(user_response) + if (user_response != 'exit'): + self.ui.plainTextEdit.appendPlainText("Alis: "+response.replace("tg",self.operator.name)) + else: + self.flag = False + self.ui.plainTextEdit.appendPlainText("Alis: Thanks for conversations,Bye...") + self.destroy() + self.ui.lineEdit.clear() + def change(self): + conn=sqlite3.connect("database.db") + c=conn.cursor() + a=data() + c.execute("SELECT * from data") + datas=c.fetchall()[0] + a.ui.lineEdit.setText(datas[1]) + date=datas[2].split("-") + a.ui.dateEdit.setDate(QDate(int(date[-1]),int(date[-2]),int(date[-3]))) + a.exec() + try: + c.execute("UPDATE data set name='{}' where id=1".format(a.name)) + c.execute("UPDATE data set date='{}' where id=1".format(a.date)) + conn.commit() + self.operator.name=a.name + except: + pass + c.close() +class data(QDialog): + def __init__(self): + super().__init__() + self.ui=Ui_Dialog() + self.ui.setupUi(self) + self.ui.pushButton.clicked.connect(self.enquiry) + self.show() + def enquiry(self): + self.name=self.ui.lineEdit.text() + self.date=self.ui.dateEdit.text() + if self.name==" ": + QMessageBox.warning(self,"Name Error","Please enter you name sir") + else: + QMessageBox.information(self,"Information saved","Thanks to share your information") + Gui.ui.plainTextEdit.appendPlainText("Alis: Thank to share your details {}".format(self.name)) + self.close() + def close(self): + if self.name=="": + self.ui.lineEdit.setText("Sir") + self.name="Sir" + +class project: + def __init__(self): + #nltk.download('popular') + # nltk.download('punkt') + # nltk.download('wordnet') + # Reading in the corpus + #self.TfidfVec1 = TfidfVectorizer(tokenizer=self.LemNormalize,stop_words='english') + #with open('chatbot.txt', 'r', encoding='utf8', errors='ignore') as fin: + #raw = fin.read().lower() + #self.sent_tokens = nltk.sent_tokenize(raw) # converts to list of sentences + #word_tokens = nltk.word_tokenize(raw) # converts to list of words + self.remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation) + self.lemmer = WordNetLemmatizer() + self.dataimport() + self.TfidfVec = TfidfVectorizer(tokenizer=self.LemNormalize) + self.TfidfVec.fit_transform(self.patterns) + def LemTokens(self,tokens): + return [self.lemmer.lemmatize(token) for token in tokens] + def LemNormalize(self,text): + return self.LemTokens(nltk.word_tokenize(text.lower().translate(self.remove_punct_dict))) + def dataimport(self): + file = open(r"jss.json", "r", errors="ignore").read() + data = json.loads(file) + self.patterns = [] + self.response = [] + for i in data['intents']: + self.patterns.extend(i['patterns']) + self.response.extend(i['responses']) + def database(self): + conn=sqlite3.connect("database.db") + c=conn.cursor() + try: + c.execute("SELECT * FROM data") + self.name=c.fetchall()[0][1] + c.close() + return True + except sqlite3.OperationalError: + c.execute("CREATE TABLE data(id INTEGER PRIMARY KEY AUTOINCREMENT,name,date)") + c.execute("INSERT INTO data (name,date) VALUES('Sir','01-01-2001')") + self.name="Sir" + conn.commit() + c.close() + return False + def greeting(self,sentence): + self.patterns.append(sentence) + """If user's input is a greeting, return a greeting response""" + tfidf = self.TfidfVec.fit_transform(self.patterns) + vals = cosine_similarity(tfidf[-1], tfidf) + idx = vals.argsort()[0][-2] + flat = vals.flatten() + flat.sort() + self.patterns.pop(-1) + req_tfidf = flat[-2] + if (req_tfidf == 0): + robo_response = "I am sorry! I don't understand you" + return robo_response + else: + robo_response = self.response[idx] + return robo_response +if __name__=="__main__": + app=QApplication(sys.argv) + app.setWindowIcon(QIcon(r'roboimg.png')) + Gui=gui() + Gui.show() + app.exec() \ No newline at end of file diff --git a/database.db b/database.db new file mode 100644 index 0000000..e102a39 Binary files /dev/null and b/database.db differ diff --git a/details.py b/details.py new file mode 100644 index 0000000..9d9d8e3 --- /dev/null +++ b/details.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'details.ui' +# +# Created by: PyQt5 UI code generator 5.15.0 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(290, 131) + self.label = QtWidgets.QLabel(Dialog) + self.label.setGeometry(QtCore.QRect(40, 20, 47, 13)) + font = QtGui.QFont() + font.setPointSize(11) + self.label.setFont(font) + self.label.setObjectName("label") + self.lineEdit = QtWidgets.QLineEdit(Dialog) + self.lineEdit.setGeometry(QtCore.QRect(90, 20, 171, 20)) + self.lineEdit.setObjectName("lineEdit") + self.label_2 = QtWidgets.QLabel(Dialog) + self.label_2.setGeometry(QtCore.QRect(40, 63, 47, 20)) + font = QtGui.QFont() + font.setPointSize(11) + self.label_2.setFont(font) + self.label_2.setObjectName("label_2") + self.dateEdit = QtWidgets.QDateEdit(Dialog) + self.dateEdit.setGeometry(QtCore.QRect(90, 60, 171, 22)) + self.dateEdit.setObjectName("dateEdit") + self.pushButton = QtWidgets.QPushButton(Dialog) + self.pushButton.setGeometry(QtCore.QRect(100, 100, 75, 23)) + self.pushButton.setObjectName("pushButton") + + self.retranslateUi(Dialog) + QtCore.QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QtCore.QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "Dialog")) + self.label.setText(_translate("Dialog", "Name:")) + self.label_2.setText(_translate("Dialog", "DOB:")) + self.pushButton.setText(_translate("Dialog", "Save")) diff --git a/jss.json b/jss.json new file mode 100644 index 0000000..faaf671 --- /dev/null +++ b/jss.json @@ -0,0 +1,132 @@ +{"intents": [ + {"patterns": ["Hey","Hi", "How are you", "Is anyone there", "Hello", "Good day","good","great work"], + "responses": ["Hi tg","Hello tg","Fine and you tg","Yes tg,how can i help u", "Hi tg, how can I help?" ,"Good to see you again tg","thanks tg","thanks tg for appriciation"] + }, + {"patterns": ["Bye", "See you later", "Goodbye","your welcome"], + "responses": ["See you later tg", "Have a nice day tg", "Bye tg! Come back again soon.","any time tg"] + }, + {"patterns": ["Thanks", "Thank you", "That's helpful","fine","ohh i see","hmmmmm","ok"], + "responses": ["Happy to help! tg", "welcome tg!", "My pleasure tg","very nice","ok good","hmmmmm","yah"] + }, + {"patterns": ["What's up","what's going on","Good Morning","Good Evening","Good Night","Who are you"], + "responses": ["Cool and you tg","Nothing special sir","Good Morning tg","Good Evening tg","Good Night tg","I am a Alis,a chatbot"] + }, + {"patterns": ["About your developer","Who creates you","who invented you","tell me something about you"], + "responses": ["My developer name is Yash Rajput","My developer name is Yash Rajput","My developer name is Yash Rajput","I am Alis and i am a bot"] + }, + { + "patterns": ["chatbot"], + "responses": ["A chatbot (also known as a talkbot, chatterbot, Bot, IM bot, interactive agent, or Artificial Conversational Entity) is a computer program or an artificial intelligence which conducts a conversation via auditory or textual methods. Such programs are often designed to convincingly simulate how a human would behave as a conversational partner, thereby passing the Turing test. Chatbots are typically used in dialog systems for various practical purposes including customer service or information acquisition. Some chatterbots use sophisticated natural language processing systems, but many simpler systems scan for keywords within the input, then pull a reply with the most matching keywords, or the most similar wording pattern, from a database.\nThe term \"ChatterBot\" was originally coined by Michael Mauldin (creator of the first Verbot, Julia) in 1994 to describe these conversational programs.Today, most chatbots are either accessed via virtual assistants such as Google Assistant and Amazon Alexa, via messaging apps such as Facebook Messenger or WeChat, or via individual organizations' apps and websites. Chatbots can be classified into usage categories such as conversational commerce (e-commerce via chat), analytics, communication, customer support, design, developer tools, education, entertainment, finance, food, games, health, HR, marketing, news, personal, productivity, shopping, social, sports, travel and utilities."] + }, + {"patterns": ["chatbot creation"], + "responses": ["The process of creating a chatbot follows a pattern similar to the development of a web page or a mobile app. It can be divided into Design, Building, Analytics and Maintenance."] + }, + { + "patterns": ["chatbot Design"], + "responses": ["The chatbot design is the process that defines the interaction between the user and the chatbot.The chatbot designer will define the chatbot personality, the questions that will be asked to the users, and the overall interaction.It can be viewed as a subset of the conversational design. In order to speed up this process, designers can use dedicated chatbot design tools, that allow for immediate preview, team collaboration and video export.An important part of the chatbot design is also centered around user testing. User testing can be performed following the same principles that guide the user testing of graphical interfaces."] + + }, + { + "patterns": ["chatbot building"], + "responses": ["The process of building a chatbot can be divided into two main tasks: understanding the user's intent and producing the correct answer. The first task involves understanding the user input. In order to properly understand a user input in a free text form, a Natural Language Processing Engine can be used.The second task may involve different approaches depending on the type of the response that the chatbot will generate."] + + }, + { + "patterns": ["chatbot Maintenance"], + "responses": ["To keep chatbots up to speed with changing company products and services, traditional chatbot development platforms require ongoing maintenance. This can either be in the form of an ongoing service provider or for larger enterprises in the form of an in-house chatbot training team.To eliminate these costs, some startups are experimenting with Artificial Intelligence to develop self-learning chatbots, particularly in Customer Service applications."] + + }, + { + "patterns": ["chatbot development platforms"], + "responses": ["The process of building, testing and deploying chatbots can be done on cloud based chatbot development platforms offered by cloud Platform as a Service (PaaS) providers such as Yekaliva, Oracle Cloud Platform, SnatchBot and IBM Watson.These cloud platforms provide Natural Language Processing, Artificial Intelligence and Mobile Backend as a Service for chatbot development."] + + }, + { + "patterns": ["chatbot use"], + "responses": ["Malicious chatbots are frequently used to fill chat rooms with spam and advertisements, by mimicking human behaviour and conversations or to entice people into revealing personal information, such as bank account numbers. They are commonly found on Yahoo! Messenger, Windows Live Messenger, AOL Instant Messenger and other instant messaging protocols. There has also been a published report of a chatbot used in a fake personal ad on a dating service's website."] + }, + { + "patterns": ["python programming language"], + "responses": ["Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.[28]\n\nPython is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented, and functional programming. Python is often described as a \"batteries included\" language due to its comprehensive standard library"] + }, + { + "patterns": ["C programming language"], + "responses": ["C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. Developed by Dennis Ritche"] + }, + { + "patterns": ["c++ programming language"], + "responses":["C++ (/ˌsiːˌplʌsˈplʌs/) is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or \"C with Classes\". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is available on many platforms."] + }, + { + "patterns": ["java programming language"], + "responses": ["Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible. It is intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.[18] Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but it has fewer low-level facilities than either of them. As of 2019, Java was one of the most popular programming languages in use according to GitHub,[ particularly for client-server web applications, with a reported 9 million developers."] + }, + { + "patterns": ["rbmi college"], + "responses": ["The institution was established by Mrs. Veena Mathur in 1996, as the Rakshpal Bahadur Management Institute, with the goal to provide engineering & management education. Rakshpal Bahadur College of Engineering and Technology originally had three colleges:\n\nRakshpal Bahadur Management Institute (RBMI) established in 1996, a management institute affiliated to Dr. A.P.J. Abdul Kalam Technical University (previously Uttar Pradesh Technical University)\nRakshpal Bahadur College of Pharmacy (RBCP) established in 2002, a pharmacy college affiliated to Dr. A.P.J. Abdul Kalam Technical University (previously Uttar Pradesh Technical University)\nRBMI Business School (RBMIBS) established in 2004, management institute approved by All India Council for Technical Education (AICTE)\nRakshpal Bahadur College of Engineering and Technology (RBCET) admitted its first cohort in 2008.\nApart from academics RBCET has always indulged in publishing and other activities providing their students market and industry interactions. RBCET campus, located near ITBP / Doordarshan Kendra, Badaun Road, Bareilly, six kilometers away from Bareilly railway station"] + }, + { + "patterns": ["python top package list"], + "responses": ["Pillow. Pillow is actually a fork of PIL – Python Image Library. ...\nMatplotlib. Matplotlib is a Python library that uses Python Script to write 2-dimensional graphs and plots. ...\nNumpy. Numpy is a popular array – processing package of Python. ...\nOpenCV Python. ...\nRequests. ...\nKeras. ...\nTensorFlow. ...\nTheano."] + }, + { + "patterns": ["Gui list in python"], + "responses": ["Kivy. Kivy is an OpenGL ES 2 accelerated framework for the creation of new user interfaces. ...\nPyQT. PyQT is one of the favoured cross-platform Python bindings implementing the Qt library for the Qt (owned by Nokia) application development framework. ...\nTkinter. ...\nWxPython. ...\nPyGUI. ...\nPySide"] + }, + { + "patterns": ["kivy"], + "responses": ["Kivy is a free and open source Python library for developing mobile apps and other multitouch application software with a natural user interface (NUI). It is distributed under the terms of the MIT License, and can run on Android, iOS, GNU/Linux, OS X, and Windows."] + }, + {"patterns": ["pyqt"], + "responses": ["PyQt5 is a set of Python bindings for Qt5 application framework from Digia. ... PyQt5 is implemented as a set of Python modules. It has over 620 classes and 6000 functions and methods. It is a multiplatform toolkit which runs on all major operating systems, including Unix, Windows, and Mac OS"] + }, + {"patterns": ["tkinter"], + "responses": ["Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit, and is Python's de facto standard GUI. Tkinter is included with standard Linux, Microsoft Windows and Mac OS X installs of Python. The name Tkinter comes from Tk interface."] + }, + {"patterns": ["wxpython"], + "responses": ["wxPython is a wrapper for the cross-platform GUI API (often referred to as a \"toolkit\") wxWidgets (which is written in C++) for the Python programming language. It is one of the alternatives to Tkinter. It is implemented as a Python extension module (native code)."] + }, + {"patterns": ["numpy"], + "responses": ["NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays."] + }, + { + "patterns": ["sqlite"], + "responses": ["SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private. ... SQLite generally runs faster the more memory you give it."] + }, + {"patterns": ["mysql"], + "responses": ["MySQL is a freely available open source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). SQL is the most popular language for adding, accessing and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use."] + }, + { + "patterns": ["postgresql"], + "responses": ["PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance. It was originally named POSTGRES, referring to its origins as a successor to the Ingres database developed at the University of California, Berkeley. "] + }, + { + "patterns": ["tenserflow"], + "responses": ["TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications. About."] + }, + { + "patterns": ["pyaudio"], + "responses": ["PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms. PyAudio is inspired by: ... tkSnack: cross-platform sound toolkit for Tcl/Tk and Python."] + }, + { + "patterns": ["strings in python"], + "responses": ["Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string."] + }, + { + "patterns": ["list in python"], + "responses": ["A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets "] + }, + { + "patterns": ["arrray in python"], + "responses": ["Python Arrays. An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. ... If you create arrays using the array module, all elements of the array must be of the same type."] + }, + { + "patterns": ["pandas"], + "responses": ["Pandas is a high-level data manipulation tool developed by Wes McKinney. It is built on the Numpy package and its key data structure is called the DataFrame. DataFrames allow you to store and manipulate tabular data in rows of observations and columns of variables."] + }, + { + "patterns": ["matplotlib"], + "responses":["Matplotlib produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits"] + } +] +} diff --git a/roboimg.png b/roboimg.png new file mode 100644 index 0000000..472e104 Binary files /dev/null and b/roboimg.png differ diff --git a/template.py b/template.py new file mode 100644 index 0000000..46b1143 --- /dev/null +++ b/template.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'template.ui' +# +# Created by: PyQt5 UI code generator 5.15.0 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(498, 524) + MainWindow.setMinimumSize(QtCore.QSize(498, 524)) + MainWindow.setMaximumSize(QtCore.QSize(498, 524)) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget) + self.plainTextEdit.setGeometry(QtCore.QRect(0, 0, 498, 441)) + self.plainTextEdit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) + self.plainTextEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.plainTextEdit.setReadOnly(True) + self.plainTextEdit.setObjectName("plainTextEdit") + self.pushButton = QtWidgets.QPushButton(self.centralwidget) + self.pushButton.setGeometry(QtCore.QRect(350, 440, 151, 41)) + font = QtGui.QFont() + font.setFamily("Arial") + font.setPointSize(17) + font.setItalic(True) + font.setStrikeOut(False) + font.setKerning(False) + self.pushButton.setFont(font) + self.pushButton.setObjectName("pushButton") + self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) + self.lineEdit.setGeometry(QtCore.QRect(2, 440, 351, 41)) + font = QtGui.QFont() + font.setPointSize(12) + self.lineEdit.setFont(font) + self.lineEdit.setObjectName("lineEdit") + MainWindow.setCentralWidget(self.centralwidget) + self.menubar = QtWidgets.QMenuBar(MainWindow) + self.menubar.setGeometry(QtCore.QRect(0, 0, 498, 21)) + self.menubar.setObjectName("menubar") + self.menuFile = QtWidgets.QMenu(self.menubar) + self.menuFile.setObjectName("menuFile") + MainWindow.setMenuBar(self.menubar) + self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + self.actionChange_details = QtWidgets.QAction(MainWindow) + self.actionChange_details.setObjectName("actionChange_details") + self.menuFile.addAction(self.actionChange_details) + self.menubar.addAction(self.menuFile.menuAction()) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) + self.plainTextEdit.setPlainText(_translate("MainWindow", "dsf\n" +"\n" +"")) + self.pushButton.setText(_translate("MainWindow", "SEND")) + self.menuFile.setTitle(_translate("MainWindow", "File")) + self.actionChange_details.setText(_translate("MainWindow", "Change Details"))