AI Chatbot Lab Manual
AI Chatbot Lab Manual
Aim: The aim of this project is to design a simple chatbot that can answer Frequently Asked Questions
(FAQs) about an organization using Python.
Description: The chatbot will be designed to answer basic questions about the organization, such as
its mission, vision, products, services, and contact information. The chatbot will use a dictionary to
store the FAQs and their corresponding answers. The user will be able to interact with the chatbot by
typing their questions, and the chatbot will respond with the relevant answer.
Source Code:
# Import the required libraries
import random
# Define a dictionary to store the FAQs and their answers
faqs = {
"What is the mission of your organization?": "Our mission is to provide innovative solutions to our
customers.",
"What is the vision of your organization?": "Our vision is to be the leading provider of technology
solutions.",
"What products do you offer?": "We offer a range of products, including software, hardware, and
consulting services.",
"How can I contact your organization?": "You can contact us through our website, phone, or email.",
"What are your business hours?": "Our business hours are Monday to Friday, 9am to 5pm."
}
while True:
# Get user input
user_input = input("User: ")
# Create a client
client = fbchat.Client(email, password)
def greet_user():
print("Hello! I'm here to help you identify potential diseases based on your symptoms.")
def ask_symptoms():
print("Please enter your symptoms (separated by commas): ")
symptoms = input().split(",")
symptoms = [symptom.strip() for symptom in symptoms]
return symptoms
def find_diseases(symptoms):
potential_diseases = []
for index, row in disease_db.iterrows():
disease_symptoms = row["Symptoms"].split(",")
disease_symptoms = [symptom.strip() for symptom in disease_symptoms]
matching_symptoms = [symptom for symptom in symptoms if symptom in disease_symptoms]
if len(matching_symptoms) > 0:
probability = len(matching_symptoms) / len(disease_symptoms)
potential_diseases.append((row["Disease"], matching_symptoms, probability))
return potential_diseases
def display_results(potential_diseases):
print("Potential diseases based on your symptoms:")
for disease, symptoms, probability in potential_diseases:
print(f"Disease: {disease}")
print(f"Matching Symptoms: {', '.join(symptoms)}")
print(f"Probability: {probability:.2f}")
print()
def main():
greet_user()
symptoms = ask_symptoms()
potential_diseases = find_diseases(symptoms)
display_results(potential_diseases)
if __name__ == "__main__":
main()
Output:
Hello! I'm here to help you identify potential diseases based on your symptoms.
Please enter your symptoms (separated by commas):
fever, headache, fatigue
Potential diseases based on your symptoms:
Disease: Influenza
Matching Symptoms: fever, headache
Probability: 0.67
Disease: Malaria
Matching Symptoms: fever, fatigue
Probability: 0.50
Disease: Common Cold
Matching Symptoms: headache, fatigue
Probability: 0.33
Week - 5
Aim: The aim of this chatbot is to assist customers in finding and purchasing products from an online
store.
Description: The chatbot will interact with the customer, asking for their preferences and
requirements, and then provide a list of recommended products. The customer can then select a
product to view its details, and finally, place an order.
Source Code:
import random
# Product database
products = [
{"id": 1, "name": "Apple iPhone", "price": 999, "description": "Latest iPhone model"},
{"id": 2, "name": "Samsung TV", "price": 1299, "description": "4K UHD TV with HDR"},
{"id": 3, "name": "Nike Shoes", "price": 79, "description": "Comfortable and stylish shoes"},
# ...
]
def greet_customer():
print("Hello! Welcome to our online store. How can I assist you today?")
def ask_preferences():
print("What type of product are you looking for?")
print("1. Electronics")
print("2. Fashion")
print("3. Home Goods")
choice = int(input("Enter your choice: "))
if choice == 1:
return "Electronics"
elif choice == 2:
return "Fashion"
else:
return "Home Goods"
def recommend_products(preferences):
recommended_products = []
for product in products:
if product["category"] == preferences:
recommended_products.append(product)
return recommended_products
def display_products(products):
print("Here are some recommended products:")
for product in products:
print(f"ID: {product['id']}, Name: {product['name']}, Price: ${product['price']}")
def ask_product_details():
product_id = int(input("Enter the ID of the product you're interested in: "))
for product in products:
if product["id"] == product_id:
print(f"Product Details: {product['description']}")
return product
print("Product not found!")
def place_order(product):
print(f"Thank you for purchasing {product['name']}!")
print("Your order has been placed successfully.")
def main():
greet_customer()
preferences = ask_preferences()
recommended_products = recommend_products(preferences)
display_products(recommended_products)
product = ask_product_details()
place_order(product)
if __name__ == "__main__":
main()
Output:
Hello! Welcome to our online store. How can I assist you today?
What type of product are you looking for?
1. Electronics
2. Fashion
3. Home Goods
Enter your choice: 1
Here are some recommended products:
ID: 1, Name: Apple iPhone, Price: $999
ID: 2, Name: Samsung TV, Price: $1299
Enter the ID of the product you're interested in: 1
Product Details: Latest iPhone model
Thank you for purchasing Apple iPhone!
Your order has been placed successfully.
Week – 6
Aim: The aim of this chatbot is to assist tourists in planning their trips by providing information about
popular destinations, attractions, and activities.
Description: The chatbot will interact with the tourist, asking for their preferences and requirements,
and then provide a personalized travel plan. The chatbot will offer suggestions for destinations,
attractions, and activities based on the tourist's interests and budget.
Source Code:
import random
# Destination database
destinations = [
{"id": 1, "name": "Paris", "description": "City of love and romance", "attractions": ["Eiffel Tower",
"Louvre Museum"]},
{"id": 2, "name": "New York City", "description": "City that never sleeps", "attractions": ["Statue of
Liberty", "Central Park"]},
{"id": 3, "name": "Tokyo", "description": "Vibrant city with rich culture", "attractions": ["Tokyo Tower",
"Shibuya Crossing"]},
# ...
]
# Activity database
activities = [
{"id": 1, "name": "Sightseeing", "description": "Explore popular landmarks"},
{"id": 2, "name": "Food Tour", "description": "Taste local cuisine"},
{"id": 3, "name": "Adventure", "description": "Go hiking or biking"},
# ...
]
def greet_tourist():
print("Hello! Welcome to our tourism chatbot. How can I assist you in planning your trip?")
def ask_destination_preferences():
print("What type of destination are you interested in?")
print("1. City Break")
print("2. Beach Vacation")
print("3. Nature Escape")
choice = int(input("Enter your choice: "))
if choice == 1:
return "City Break"
elif choice == 2:
return "Beach Vacation"
else:
return "Nature Escape"
def recommend_destinations(preferences):
recommended_destinations = []
for destination in destinations:
if destination["category"] == preferences:
recommended_destinations.append(destination)
return recommended_destinations
def display_destinations(destinations):
print("Here are some recommended destinations:")
for destination in destinations:
print(f"ID: {destination['id']}, Name: {destination['name']}, Description:
{destination['description']}")
def ask_activity_preferences():
print("What type of activity are you interested in?")
print("1. Sightseeing")
print("2. Food Tour")
print("3. Adventure")
choice = int(input("Enter your choice: "))
if choice == 1:
return "Sightseeing"
elif choice == 2:
return "Food Tour"
else:
return "Adventure"
def recommend_activities(preferences):
recommended_activities = []
for activity in activities:
if activity["category"] == preferences:
recommended_activities.append(activity)
return recommended_activities
def display_activities(activities):
print("Here are some recommended activities:")
for activity in activities:
print(f"ID: {activity['id']}, Name: {activity['name']}, Description: {activity['description']}")
def main():
greet_tourist()
destination_preferences = ask_destination_preferences()
recommended_destinations = recommend_destinations(destination_preferences)
display_destinations(recommended_destinations)
destination_id = int(input("Enter the ID of the destination you're interested in: "))
for destination in destinations:
if destination["id"] == destination_id:
activity_preferences = ask_activity_preferences()
recommended_activities = recommend_activities(activity_preferences)
display_activities(recommended_activities)
activity_ids = input("Enter the IDs of the activities you're interested in (separated by commas): ")
activity_ids = [int(id) for id in activity_ids.split(",")]
activities = [activity for activity in activities if activity["id"] in activity_ids]
create_travel_plan(destination, activities)
break
if __name__ == "__main__":
main()
Output:
Hello! Welcome to our tourism chatbot. How can I assist you in planning your trip?
What type of destination are you interested in?
1. City Break
2. Beach Vacation
3. Nature Escape
Enter your choice: 1
Here are some recommended destinations:
ID: 1, Name: Paris, Description: City of love and romance
ID: 2, Name: New York City, Description: City that never sleeps
Enter the ID of the destination you're interested in: 1
What type of activity are you interested in?
1. Sightseeing
2. Food Tour
3. Adventure
Enter your choice: 1
Here are some recommended activities:
ID: 1, Name: Sightseeing, Description: Explore popular landmarks
Enter the IDs of the activities you're interested in (separated by commas): 1
Your travel plan for Paris:
Attractions: Eiffel Tower, Louvre Museum
Activities: Sightseeing
Week – 7
Aim: The aim of this chatbot is to assist patients with insomnia by providing personalized guidance
and relaxation techniques to help them fall asleep.
Description: The chatbot will interact with the patient, asking about their sleep patterns, stress levels,
and relaxation preferences. Based on the patient's input, the chatbot will provide a customized sleep
plan, including relaxation techniques, sleep hygiene tips, and stress management strategies.
Source Code:
import random
# Relaxation techniques database
relaxation_techniques = [
{"id": 1, "name": "Deep Breathing", "description": "Breathe in deeply through your nose, hold for 5
seconds, and exhale slowly"},
{"id": 2, "name": "Progressive Muscle Relaxation", "description": "Tense and then relax different
muscle groups in your body"},
{"id": 3, "name": "Mindfulness Meditation", "description": "Focus on the present moment, without
judgment"},
{"id": 4, "name": "Visualization", "description": "Imagine yourself in a peaceful, relaxing
environment"},
{"id": 5, "name": "Yoga", "description": "Practice gentle stretches and movements to relax your body
and mind"}
]
def ask_sleep_patterns():
print("How many hours of sleep do you typically get per night?")
hours = int(input("Enter the number of hours: "))
print("Do you have trouble falling asleep, staying asleep, or both?")
trouble = input("Enter 'falling asleep', 'staying asleep', or 'both': ")
return hours, trouble
def recommend_relaxation_techniques(trouble):
recommended_techniques = []
if trouble == "falling asleep":
recommended_techniques.append(relaxation_techniques[0]) # Deep Breathing
elif trouble == "staying asleep":
recommended_techniques.append(relaxation_techniques[1]) # Progressive Muscle Relaxation
else:
recommended_techniques.append(relaxation_techniques[2]) # Mindfulness Meditation
return recommended_techniques
def display_relaxation_techniques(techniques):
print("Here are some recommended relaxation techniques:")
for technique in techniques:
print(f"ID: {technique['id']}, Name: {technique['name']}, Description: {technique['description']}")
def ask_stress_levels():
print("How would you rate your current stress level?")
print("1. Low")
print("2. Medium")
print("3. High")
choice = int(input("Enter your choice: "))
if choice == 1:
return "Low"
elif choice == 2:
return "Medium"
else:
return "High"
def recommend_sleep_hygiene_tips(stress_level):
recommended_tips = []
if stress_level == "Low":
recommended_tips.append(sleep_hygiene_tips[0]) # Establish a Bedtime Routine
elif stress_level == "Medium":
recommended_tips.append(sleep_hygiene_tips[1]) # Create a Sleep-Conducive Environment
else:
recommended_tips.append(sleep_hygiene_tips[2]) # Avoid Stimulating Activities Before Bed
return recommended_tips
def display_sleep_hygiene_tips(tips):
print("Here are some recommended sleep hygiene tips:")
for tip in tips:
print(f"ID: {tip['id']}, Name: {tip['name']}, Description: {tip['description']}")
def main():
greet_patient()
hours, trouble = ask_sleep_patterns()
recommended_techniques = recommend_relaxation_techniques(trouble)
display_relaxation_techniques(recommended_techniques)
stress_level = ask_stress_levels()
recommended_tips = recommend_sleep_hygiene_tips(stress_level)
display_sleep_hygiene_tips(recommended_tips)
create_sleep_plan(recommended_techniques, recommended_tips)
if __name__ == "__main__":
main()
Output:
Hello! Welcome to our insomnia chatbot. How can I assist you in improving your sleep?
How many hours of sleep do you typically get per night?
Enter the number of hours: 6
Do you have trouble falling asleep, staying asleep, or both?
Enter 'falling asleep', 'staying asleep', or 'both': falling asleep
Here are some recommended relaxation techniques:
ID: 1, Name: Deep Breathing, Description: Breathe in deeply through your nose, hold for 5 seconds,
and exhale slowly
ID: 3, Name: Mindfulness Meditation, Description: Focus on the present moment, without judgment
How would you rate your current stress level?
1. Low
2. Medium
3. High
Enter your choice: 2
Here are some recommended sleep hygiene tips:
ID: 1, Name: Establish a Bedtime Routine, Description: Develop a calming pre-sleep routine to signal
your body that it's time to sleep
ID: 2, Name: Create a Sleep-Conducive Environment, Description: Make your bedroom a sleep haven
by ensuring it is dark, quiet, and cool
Here is your personalized sleep plan:
Relaxation Techniques:
ID: 1, Name: Deep Breathing, Description: Breathe in deeply through your nose, hold for 5 seconds,
and exhale slowly
ID: 3, Name: Mindfulness Meditation, Description: Focus on the present moment, without judgment
Sleep Hygiene Tips:
ID: 1, Name: Establish a Bedtime Routine, Description: Develop a calming pre-sleep routine to signal
your body that it's time to sleep
ID: 2, Name: Create a Sleep-Conducive Environment, Description: Make your bedroom a sleep haven
by ensuring it is dark, quiet, and cool