├── AI chatbot ├── chatbotmodel.h5 ├── classes.pkl ├── intents.json ├── main.py ├── trainingData.py └── words.pkl ├── LICENSE └── README.md /AI chatbot/chatbotmodel.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpd/AI-chatbot-python/54efa7cb3c9232cc1d8999b61934f391e7d1338d/AI chatbot/chatbotmodel.h5 -------------------------------------------------------------------------------- /AI chatbot/classes.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpd/AI-chatbot-python/54efa7cb3c9232cc1d8999b61934f391e7d1338d/AI chatbot/classes.pkl -------------------------------------------------------------------------------- /AI chatbot/intents.json: -------------------------------------------------------------------------------- 1 | {"intents": [ 2 | {"tag": "greetings", 3 | "patterns": ["hello","hey","hi","good day","Greetings","what's up?","how is it going?"], 4 | "responses": ["Hello!","Hey!","What can I do for you?"] 5 | }, 6 | 7 | {"tag": "name", 8 | "patterns": ["what is your name","name","what's your name","who are you","what should I call you"], 9 | "responses": ["You can call me Ribot","I'm Ribot","I'm Ribot your virtual assistant"] 10 | }, 11 | 12 | {"tag": "courses", 13 | "patterns": ["what courses are available", "how many courses are there in this college"], 14 | "responses": ["Informatics College Pokhara has been in direct partnership with London Metropolitan University, \nUK to provide enviable higher education in IT and Business to students in Pokhara.\nFor Bachelors Degree in Information Technology we have been offering the specialization in BSc (Hons) Computing.\nFor Bachelors in Business Administration we have been offering the followings:\n\n1. BBA (Marketing) with International Business \n\n2. BBA (Accounting & Finance) with International Business\n\n3. BBA (International Business)"] 15 | }, 16 | 17 | {"tag": "courseDuration", 18 | "patterns": ["how long will be BIT or BBA course", "how long will it take to complete BIT or BBA course"], 19 | "responses": ["Our college offers 3 year long BIT course and 3 and half year long BBA course."] 20 | }, 21 | 22 | {"tag": "Location", 23 | "patterns": ["location","where is it located","what is the location of the college"], 24 | "responses": ["Informatics College Pokhara is located in Matepani-12, pokhara near Gandaki Hospital."] 25 | }, 26 | 27 | {"tag": "semesters", 28 | "patterns": ["how many semesters are there in a year","how many semesters one should study in a year"], 29 | "responses": ["There are two semesters in a year."] 30 | }, 31 | 32 | {"tag": "semDuration", 33 | "patterns": ["how many months are there in a semester","how long will be a single semester"], 34 | "responses": ["The single semester will be around 4 months."] 35 | }, 36 | 37 | {"tag": "studentRequirements", 38 | "patterns": ["what are the student requirements for admission","entry requirements","admission requirements"], 39 | "responses": ["Academic Level\nNEB +2 overall aggregate of 2.2 CGPA (55%) or above with each subject (theory and practical) grade D+ or above, and SEE Mathematics score of C+ ( 50%) or above.\nFor A-Levels, a minimum of 3.5 credits and atleast a grade of D and above.\n\nEnglish Proficiency\nEnglish NEB XII Marks greater or equals to 60% or 2.4 GPA\nFor Level 4 or Year 1 BIT\nPass in General Paper or English Language or IELTS 5.5 or PTE 47/ Meeting UCAS Tariff points of 80.\nFor Level 4 or Year 1 BBA\nPass in General Paper or English Language or IELTS 5.5 or PTE 47/ Meeting UCAS Tariff points of 96."] 40 | }, 41 | 42 | {"tag": "classes", 43 | "patterns": ["how many classes will be there in a day","how long are the classes?"], 44 | "responses": ["There may be two or three classes per day. Each class will be of 1 hour and 30 minutes."] 45 | }, 46 | 47 | {"tag": "teachingStyle", 48 | "patterns": ["what is the teaching style of this college?","Is the teaching pattern different from other college?","what is the teaching format?"], 49 | "responses": ["Our college has different teaching patterns than other colleges of Nepal. We adopt a British teaching methodology, following the LTW techniques which stands for Lecture, Tutorial and Workshop.\nYou can provide us with your contact details and our counselors shall reach out to you and provide you with further details."] 50 | }, 51 | 52 | {"tag": "exams", 53 | "patterns": ["what are the exams like?","What is the exam pattern"], 54 | "responses": ["There are assignments which carry more weight than your written exams. The assignments have deadlines which you should not exceed if you want to get better marks."] 55 | }, 56 | 57 | {"tag": "hours", 58 | "patterns": ["what are your hours","when are you guys open","what your hours of operation"], 59 | "responses": ["You can message us here at any hours. But our college premises will be open from 7:00 am to 5:00 pm only."] 60 | }, 61 | 62 | {"tag": "funActivities", 63 | "patterns": ["will there be any extra curriculum activities?","does the college conducts any fun program"], 64 | "responses": ["Yes, Of course. Our college not only provides excellent education but also encourage students to take part in different curriculum activities. The college conducts yearly programs like Sports meet, Carnival, Holi festival, and Christmas. \n Also our college has basketball court, badminton court, table tennis, chess, carrom board and many more refreshment zones."] 65 | }, 66 | 67 | {"tag": "facilities", 68 | "patterns": ["what facilities are provided by the college?","what are the facilities of college for students", "what are the college infrastructures "], 69 | "responses": ["With excellent education facilities, Our College provides various other facilities like 24 hours internet, library, classes with AC, discusson room, canteen, parking space, and student service for any students queries."] 70 | }, 71 | 72 | {"tag": "fee", 73 | "patterns": ["how much is the college fee","what is the fee structure"], 74 | "responses": ["Course BIT\nAdmission fee=RS 96,000\nYear 1\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 69,000 Total fee= RS 334,000\nYear 2\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 69,000 Total fee= RS 238,000\nYear 3\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 69,000 Total fee= RS 238,000\nGrandTotal fee= RS 810,000\n\nCourse BBA\nAdmission fee=RS 96,000\nYear 1\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 52,000 Total fee= RS 300,000\nYear 2\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 52,000 Total fee= RS 204,000\nYear 3\nUniversity and Exam fee= RS 100,000 Each semester fee=RS 52,000 Total fee= RS 204,000\nYear 4\nUniversity and Exam fee= RS 50,000 Semester fee=RS 52,000 Total fee= RS 102,000\nGrandTotal fee= RS 810,000"] 75 | }, 76 | 77 | {"tag": "goodbye", 78 | "patterns": ["cya","See you later","Goodbye","I am leaving","Have a Good Day","bye","see ya"], 79 | "responses": ["Sad to see you go :(","Talk you later","Goodbye"] 80 | }, 81 | 82 | {"tag": "invalid", 83 | "patterns": ["","gvsd","asbhk"], 84 | "responses": ["Sorry, can't understand you", "Please give me more info", "Not sure I understand"] 85 | }, 86 | 87 | {"tag": "thanks", 88 | "patterns": ["Thanks", "Thank you", "That's helpful", "Awesome, thanks", "Thanks for helping me"], 89 | "responses": ["Happy to help!", "Any time!", "My pleasure"] 90 | } 91 | ]} -------------------------------------------------------------------------------- /AI chatbot/main.py: -------------------------------------------------------------------------------- 1 | ### Author: EricPd ### 2 | ### College Project ### 3 | 4 | import random 5 | import json 6 | import pickle 7 | import numpy as np 8 | 9 | import nltk 10 | from nltk.stem import WordNetLemmatizer 11 | 12 | from tensorflow.keras.models import load_model 13 | 14 | 15 | lemmatizer = WordNetLemmatizer() 16 | 17 | intents = json.loads(open('intents.json').read()) 18 | 19 | words = pickle.load(open('words.pkl', 'rb')) 20 | classes = pickle.load(open('classes.pkl', 'rb')) 21 | model = load_model('chatbotmodel.h5') 22 | 23 | def clean_up_sentence(sentence): 24 | sentence_words = nltk.word_tokenize(sentence) 25 | sentence_words = [lemmatizer.lemmatize(word) for word in sentence_words] 26 | return sentence_words 27 | 28 | def bag_of_words(sentence): 29 | sentence_words= clean_up_sentence(sentence) 30 | bag = [0] * len(words) 31 | for w in sentence_words: 32 | for i, word in enumerate(words): 33 | if word == w: 34 | bag[i] = 1 35 | 36 | return np.array(bag) 37 | 38 | def predict_class(sentence): 39 | bow = bag_of_words(sentence) 40 | res = model.predict(np.array([bow]))[0] 41 | ERROR_THRESHOLD = 0.25 42 | results = [[i,r] for i, r in enumerate(res) if r > ERROR_THRESHOLD] 43 | 44 | results.sort(key=lambda x:x[1], reverse=True) 45 | return_list = [] 46 | for r in results: 47 | return_list.append({'intent': classes[r[0]], 'probability': str(r[1])}) 48 | return return_list 49 | 50 | 51 | def get_response(intents_list,intents_json): 52 | tag= intents_list[0]['intent'] 53 | list_of_intents =intents_json['intents'] 54 | for i in list_of_intents: 55 | if i['tag'] == tag: 56 | result = random.choice(i['responses']) 57 | break 58 | return result 59 | 60 | print("|============= Welcome to Eric Chatbot System! =============|") 61 | print("|============================== Feel Free ============================|") 62 | print("|================================== To ===============================|") 63 | print("|=============== Ask your any query about our college ================|") 64 | while True: 65 | message = input("| You: ") 66 | if message == "bye" or message == "Goodbye": 67 | ints = predict_class(message) 68 | res = get_response(ints, intents) 69 | print("| Bot:", res) 70 | print("|===================== The Program End here! =====================|") 71 | exit() 72 | 73 | else: 74 | ints = predict_class(message) 75 | res = get_response(ints, intents) 76 | print("| Bot:", res) 77 | 78 | ###add online API 79 | -------------------------------------------------------------------------------- /AI chatbot/trainingData.py: -------------------------------------------------------------------------------- 1 | ### Author: Riya Nakarmi ### 2 | ### College Project ### 3 | 4 | import random 5 | import json 6 | import pickle 7 | import numpy as np 8 | 9 | import nltk 10 | from nltk.stem import WordNetLemmatizer 11 | 12 | from tensorflow.keras.models import Sequential 13 | from tensorflow.keras.layers import Dense, Activation, Dropout 14 | from tensorflow.keras.optimizers import SGD 15 | 16 | lemmatizer = WordNetLemmatizer() 17 | 18 | intents = json.loads(open('intents.json').read()) 19 | 20 | words = [] 21 | classes = [] 22 | documents = [] 23 | ignore_letters = ['?', '!',',','.'] 24 | 25 | for intent in intents['intents']: 26 | for pattern in intent['patterns']: 27 | word_list = nltk.word_tokenize(pattern) 28 | words.extend(word_list) 29 | documents.append((word_list,intent['tag'])) 30 | if intent['tag'] not in classes: 31 | classes.append(intent['tag']) 32 | 33 | words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letters] 34 | words = sorted(set(words)) 35 | 36 | classes = sorted(set(classes)) 37 | 38 | pickle.dump(words, open('words.pkl', 'wb')) 39 | pickle.dump(classes, open('classes.pkl', 'wb')) 40 | 41 | training = [] 42 | output_empty = [0] * len(classes) 43 | 44 | for document in documents: 45 | bag =[] 46 | word_patterns = document[0] 47 | word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns] 48 | for word in words: 49 | bag.append(1) if word in word_patterns else bag.append(0) 50 | 51 | output_row = list(output_empty) 52 | output_row[classes.index(document[1])] = 1 53 | training.append([bag, output_row]) 54 | 55 | random.shuffle(training) 56 | training = np.array(training) 57 | 58 | train_x = list(training[:, 0]) 59 | train_y = list(training[:, 1]) 60 | 61 | model = Sequential() 62 | model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu')) 63 | model.add(Dropout(0.5)) 64 | model.add(Dense(64, activation='relu')) 65 | model.add(Dropout(0.5)) 66 | model.add(Dense(len(train_y[0]), activation='softmax')) 67 | 68 | sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) 69 | model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy']) 70 | hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1) 71 | model.save('chatbotmodel.h5', hist) 72 | 73 | print('Done') -------------------------------------------------------------------------------- /AI chatbot/words.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpd/AI-chatbot-python/54efa7cb3c9232cc1d8999b61934f391e7d1338d/AI chatbot/words.pkl -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ericpd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # AI-chatbot-python 3 | The AI chatbot is a automatic communicating system for a college inquiry. Here, the user has to place their queries as input, and the system bot replies according to the question. This system can play a very convenient and time-saving role in delivering the required information about the college to those who inquiry .... 4 | 5 | 6 | ![ac](https://user-images.githubusercontent.com/17751104/161262593-2a32d051-7625-4a06-9fe2-66a4e5224a79.png) 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------