Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Artificial Intelligence 18SE02CE051

SECE4042 CE Batch-C

PPSU Chatbot

Code:

import string
import random

inputs_greet = ("hello", "hi", "hey")


responses_greet = ["hi", "hey", "hi there", "hello"]

def greet(sentence):
for word in sentence.split():
if word.lower() in inputs_greet:
return random.choice(responses_greet)

inputs_about = ("about", "about ppsu", "about p p savani university")


responses_about = ["P P Savani University, one of the leading Knowledge City is a fully
integrated higher education facility for the students across the globe."]

def about(sentence):
for word in sentence.split():
if word.lower() in inputs_about:
return random.choice(responses_about)

inputs_school = ("school", "schools", "course", "courses")


responses_school = ["Sciences, Engineering, Architecture & Planning, Design, Physiotherapy,
Nursing, Liberal Arts & Management Studies, Homoeopathy"]

def school(sentence):
for word in sentence.split():
if word.lower() in inputs_school:
return random.choice(responses_school)

inputs_eng = ("engineering", "soe", "engineer", "b.tech")


responses_eng = ["Mechanical Engineering, Computer Engineering, Chemical Engineering,
Civil Engineering, Information Technology"]

def eng(sentence):
for word in sentence.split():
if word.lower() in inputs_eng:
return random.choice(responses_eng)

inputs_comp = ("ce", "computer", "computer engineering", "cse")


responses_comp = ["\n\tComputer Engineering is not limited to only programming but it
generates numerous opportunities in hardware and software development,web-development,
Computer Support Specialist, Computer Systems Analyst, Computer Systems Designer,
Database Administrator, Network Administratorand much more.\n\tIt is the scientific and
P. P. SAVANI UNIVERSITY 1
Artificial Intelligence 18SE02CE051
SECE4042 CE Batch-C

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)

inputs_contact = ("contact", "mobile", "helpline", "mail", "email")


responses_contact = ["TOLL FREE NO. - 1800 212 5521 ,Admission Helpline - +91
9512035667, admission@ppsu.ac.in, info@ppsu.ac.in"]

def contact(sentence):
for word in sentence.split():
if word.lower() in inputs_contact:
return random.choice(responses_contact)

inputs_address = ("address", "add", "location", "where")


responses_address = ["NH 8, GETCO, Near Biltech, Village: Dhamdod, Kosamba, Dist.: Surat -
394125."]

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

You might also like