NEP -AI-LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

PART B

PROGRAM B1 . . .
DOWNLOAD PDF - AI LAB MANUAL

 
   


7.Write a program to implement Simple Chatbot Program using python

def chatbot_response(user_input):
    # Convert the input to lowercase to make the bot case insensitive
    user_input = user_input.lower()

    # Simple keyword-based responses
    if "hello" in user_input or "hi" in user_input:
        return "Hello! How can I help you today?"
    elif "how are you" in user_input:
        return "I'm just a bot, but I'm here to help you! How can I assist you?"
    elif "name" in user_input:
        return "I am a chatbot created by OpenAI. What's your name?"
    elif "bye" in user_input or "goodbye" in user_input:
        return "Goodbye! Have a great day!"
    else:
        return "I'm sorry, I don't understand that. Can you rephrase?"

# Main loop to interact with the chatbot
print("Welcome to the simple chatbot. Type 'bye' to exit.")
while True:
    user_input = input("You: ")
    if user_input.lower() == "bye":
        print("Chatbot: Goodbye! Have a great day!")
        break
    response = chatbot_response(user_input)
    print("Chatbot:", response)



OUTPUT: 

Welcome to the simple chatbot. Type 'bye' to exit.
You: d
Chatbot: I'm sorry, I don't understand that. Can you rephrase?
 
You: hi
Chatbot: Hello! How can I help you today?
You: d
 
You: bye
Chatbot: Goodbye! Have a great day!