Professional Documents
Culture Documents
PPSUChatbot 18SE02CE051
PPSUChatbot 18SE02CE051
SECE4042 CE Batch-C
PPSU Chatbot
Code:
import string
import random
def greet(sentence):
for word in sentence.split():
if word.lower() in inputs_greet:
return random.choice(responses_greet)
def about(sentence):
for word in sentence.split():
if word.lower() in inputs_about:
return random.choice(responses_about)
def school(sentence):
for word in sentence.split():
if word.lower() in inputs_school:
return random.choice(responses_school)
def eng(sentence):
for word in sentence.split():
if word.lower() in inputs_eng:
return random.choice(responses_eng)
practical approach to computation and its applications.\n\tCE/IT are the sectors that can
never likely to reach saturation and thus can be considered a positive ray of hope for the
prosperous career ahead.\n\tThe department is established with the objective of imparting
quality education in the field of Computer Science.\n\tThe department has modern facilities
for teaching, learning and research.\n\tThe department offers a wide array of research
opportunities and programs of study at undergraduate and postgraduate level.\n\
tDepartment consists of well-equipped laboratories for separate computing platforms,
enabling the students to work with different cutting edges and hot cake technologies.\n\
tEnough laboratory time is made available to the students for maximum utilization of the
computing facilities.\n\tOur main strength is highly qualified & experienced faculty members,
who are very enthusiastic about learning new technologies and updating their skill sets.\n\
tFaculty members are always ready to guide students apart from regular teaching hours and
maintaining the disciplined behavior in the departments.\n\tThe department is providing the
latest, quality education and fulfilling growing needs for the skilled professionals, of the ever
changing Software Industryand the IT world."]
def comp(sentence):
for word in sentence.split():
if word.lower() in inputs_comp:
return random.choice(responses_comp)
def contact(sentence):
for word in sentence.split():
if word.lower() in inputs_contact:
return random.choice(responses_contact)
def address(sentence):
for word in sentence.split():
if word.lower() in inputs_address:
return random.choice(responses_address)
def response(user_response):
robo1_response = ''
TfidfVec = TfidfVectorizer(tokenizer=lemnormalize, stop_words='english')
tfidf = TfidfVec.fit_transform(sent_tokens)
vals = cosine_similarity(tfidf[-1], tfidf)
idx = vals.argsort()[0][-2]
flat = vals.flatten()
flat.sort()
req_tfidf = flat[-2]
P. P. SAVANI UNIVERSITY 2
Artificial Intelligence 18SE02CE051
SECE4042 CE Batch-C
if (req_tfidf == 0):
robo1_response = robo1_response + "I am sorry! I don't understand you"
return robo1_response
else:
robo1_response = robo1_response + sent_tokens[idx]
return robo1_response
flag = True
print("BOT: I'm PPSU BOT. Let's have a conversation!, if you want exit, just type Bye")
while (flag == True):
user_response = input()
user_response = user_response.lower()
if (user_response != 'bye'):
if (user_response == 'thanks' or user_response == 'thank you'):
flag = False
print("BOT: You are welcome...")
else:
if (greet(user_response) != None):
print("BOT: " + greet(user_response))
elif (about(user_response) != None):
print("BOT: " + about(user_response))
elif (school(user_response) != None):
print("BOT: " + school(user_response))
elif (contact(user_response) != None):
print("BOT: " + contact(user_response))
elif (address(user_response) != None):
print("BOT: " + address(user_response))
elif (comp(user_response) != None):
print("BOT: " + comp(user_response))
elif (eng(user_response) != None):
print("BOT: " + eng(user_response))
else:
print("BOT: I am sorry! I don't understand you")
else:
flag = False
print("BOT: Goodbye!")
Output:
P. P. SAVANI UNIVERSITY 3
Artificial Intelligence 18SE02CE051
SECE4042 CE Batch-C
P. P. SAVANI UNIVERSITY 4