BetaB0T (1) Pandey
BetaB0T (1) Pandey
ON
“AI CHATBOT USING PYTHON”
HRISHIKESH JAGTAP
DHANANJAY PANDEY
SIDDHANT KADAM
VIJAY PATIL
Department of INFORMATION
TECHNOLOGY
CERTIFICATE
ACKNOWLEDGEMENT
We would like to thank Head of the Department, Mrs. Jagruti Patil, for
providing the resources and facilities necessary for the completion of
this project. Your dedication to the department and its students is truly
commendable.
ABSTRACT
In the realm of virtual assistants, this Python code brings to life BetaBot, a helpful
companion ready to tackle your information needs and basic calculations. Built
with Tkinter, BetaBot boasts a user-friendly graphical interface, featuring a
conversation window, a dedicated space for you to type your queries, and buttons
for search, accessing past searches, and even switching to fullscreen mode.
But BetaBot's talents extend beyond information retrieval. It can also handle basic
mathematical calculations, transforming the expression you enter into a numerical
solution. To make your life even easier, BetaBot keeps track of your recent search
history in a handy database. Whenever you feel the need to revisit past inquiries, a
dedicated button grants you access to this log.
And that's not all! BetaBot is built with resilience in mind. It incorporates error
handling mechanisms to navigate unexpected situations. Whether it encounters
network issues during a DuckDuckGo search or stumbles upon challenges while
processing information from Wikipedia or tackling your math problems, BetaBot
will handle them gracefully, ensuring a smooth and informative experience.
In essence, this code empowers you with a versatile virtual assistant, ever ready to
answer your questions, perform calculations, and store your search history for
convenient access. All this wrapped up in a user-friendly interface, making
BetaBot a valuable companion for your digital endeavors.
INDEX
1. Introduction ………………...…………………………………………………………………...4
2. Literature Survey ….….……..……….………………………………………………………...6
3. Problem Definition …..…...…..…………………………………………………………………8
4. Existing System……...….….……..………………………………………………………..…….10
5. Proposed System …....…….…………………………………………………………………....13
6. Algorithm…………....….……………………………………………………………………….17
7. Methodology…………..………..……………………………………………………………….20
7.1 Activity Diagram……………………………………………………………………………...23
7.2 Sequence Diagram…………………………………………………………………………….24
7.3 Flowchart………………………………………………………………………………………25
8. Program Code…………..………………………………………………………………………….26
9. Screenshot………………….………………………………………………………………………...37
10. Testing…………………..……………………………………………………………………….….43
10.1 Unit Testing………………………………………………………………………………...…44
10.2 Integration Testing………………………………………………………………………...…..45
10.3 Validation Testing………………………………………………………………………..……46
10.4 White-Box Testing…………………………………………………………………….………47
11. System Requirement……….………………………………………………………………………48
11.1 Hardware Requirement………………………………………………………………………..47
11.2 Software Requirement………………………………………………………....……………..48
12. Advantages………………………………………………………………………..………………..49
13. Conclusion ………………………………………………………………………..………………..50
14. Reference……………………………………………………………………….…………………..51
1. INTRODUCTION
The digital landscape continues to evolve at a rapid pace, constantly
introducing new tools and technologies that streamline our lives and enhance our
access to information. In this ever-growing ecosystem, virtual assistants have
emerged as powerful companions, offering a helping hand in navigating the vast
ocean of knowledge and completing everyday tasks. This document delves into the
intricate workings of a Python code designed to create a virtual assistant named
BetaBot.
Throughout the subsequent sections, we will delve deeper into the code's structure,
meticulously analyzing each component and its role in orchestrating BetaBot's
impressive skillset. We will begin by scrutinizing the graphical user interface,
deconstructing its elements and understanding how they contribute to a user-
friendly experience. Next, we will embark on an exploration of BetaBot's
information retrieval prowess. Witnessing its seamless integration with external
sources like DuckDuckGo and Wikipedia will shed light on how it efficiently
gathers and presents relevant information.
Furthermore, we will unveil the secrets behind BetaBot's ability to tackle basic
mathematical expressions. By dissecting the code responsible for calculations, we
will gain a profound understanding of its internal processing mechanism. Finally,
the concept of a personal search history will be meticulously examined, revealing
how BetaBot meticulously stores and retrieves past user queries.
This introductory chapter has laid the groundwork for our in-depth exploration.
Brace yourself as we embark on a fascinating journey to unveil the intricate
workings of BetaBot, your personal digital assistant which saves your efforts by
giving accurate results without irrelevant Information.
2. LITERARTURE SURVEY
The late 2000s witnessed the rise of mobile virtual assistants (MVAs) with the
widespread adoption of smartphones. The launch of Siri by Apple in 2011
demonstrated the potential of VAs on mobile devices, leveraging features like
location awareness and internet connectivity to offer contextually aware
experiences. Furthermore, the integration of artificial intelligence (AI) techniques
such as machine learning and deep learning has enhanced VAs' adaptability and
personalized assistance capabilities. (Harper et al., 2015; Russell & Norvig, 2021).
Virtual assistants find applications across various domains, from personal use to
business environments. In personal settings, VAs assist with tasks such as
scheduling, reminders, and controlling smart home devices. In businesses, they
handle customer service interactions, appointment scheduling, and product
information retrieval. (Gartner, 2023)Despite advancements, challenges persist in
VA development, including natural language ambiguity and context dependence.
Ethical considerations such as data privacy and AI bias necessitate careful
attention. (Etzioni & Etzioni, 2017).
3. PROBLEM DEFINITION
This project focuses on the development of a core virtual assistant framework. The
initial functionalities will target information retrieval through DuckDuckGo and
Wikipedia integration, basic mathematical calculations, and a basic user interface
for interaction. Future iterations may explore advanced features like:
4. EXISTING SYSTEM
Prominent Players:
Amazon Alexa: A frontrunner in the smart home assistant domain, Alexa excels in
controlling smart devices and enabling voice-activated interactions for various
tasks. Its strength lies in its extensive ecosystem of compatible smart home
devices.
GoogleAssistant: Renowned for its robust search capabilities and integration with
Google services, Google Assistant offers a comprehensive information retrieval
experience and smooth interaction with other Google products. Nonetheless, its
customization options may be comparatively narrower than those of some
competitors.
Future Prospects:
5. PROPOSED SYSTEM
System Architecture:
1. Graphical User Interface (GUI): The GUI serves as the primary point of
interaction between BetaBot and the user. It will consist of the following
elements:
o Conversation window: This window displays the conversation history,
with user queries presented on the left and BetaBot's responses on the
right.
o User input field: This field allows users to type their questions or
The interaction between the user and BetaBot follows a well-defined workflow:
1. User Input: The user types their query or command into the designated
input field within the GUI.
2. Information Retrieval: BetaBot initiates the information retrieval process
based on the following sequence:
o It first queries DuckDuckGo's Instant Answers API for a direct
answer.
o If no answer is found, BetaBot searches Wikipedia and summarizes
6. Clear Option: Helps to clear the screen and deletes all the text on the
screen.
7. Mode Selection: User can select mode, Duckduckgo mode,Wiki Mode or
Default/Auto mode to make searches more powerful and accurate.
8. Summarizer: User can summarize information as per their needs by giving
commands respectively.
9. System Implementation
API
o wikipedia library for searching and summarizing Wikipedia articles
6. ALGORITHM
2. Information Retrieval
2.1. Check if the user input is a mathematical expression.
- If yes, jump to step 3 (Math Calculation).
2.2. Formulate a query for DuckDuckGo's Instant Answers API based on
the user input.
2.3. Use the `requests` library to send a GET request to the DuckDuckGo
API with the formulated query.
2.4. Parse the JSON response from DuckDuckGo.
- If a direct answer is found, display it in the conversation window and
optionally store the query and response in the database. (End of Retrieval)
- If no answer is found in DuckDuckGo:
2.5. Use the `wikipedia` library to search Wikipedia for articles related to the user
input.
2.6. If Wikipedia results are found:
- Extract a relevant snippet or summary from the first article.
- Display the summarized information in the conversation window and
optionally store the query and response in the database. (End of Retrieval)
2.7. If no Wikipedia results are found, display a message indicating no
information found.
18 Dept. of Information Technology
AI Chatbot Using Python
3. Math Calculation
3.1. Evaluate the user input as a mathematical expression using Python's `eval`
function within a try-except block.
- In case of a successful evaluation:
- Display the calculated result in the conversation window.
- In case of an evaluation error (e.g., invalid expression):
- Display an error message indicating an invalid calculation.
7. METHODOLOGY
This chapter delves into the meticulous methodology employed to create and
evaluate BetaBot, a virtual assistant designed to streamline information retrieval,
manage basic tasks, and perform calculations for its users. We embark on a journey
that encompasses software development, a comprehensive literature review, and a
rigorous evaluation process,.
This study focuses on the development of a core virtual assistant framework named
BetaBot. The scope encompasses the following functionalities:
interaction.
Limitations:
The study primarily targets two application service provider (ASP) domains:
The specific research methods employed within each category will be elaborated
upon in subsequent sections.
7.3 FLOWCHART
8. PROGRAM CODE
import tkinter as tk
import wikipedia
import re
import random
import requests
import sqlite3
class ChatBot:
self.master = master
master.title("βetaB0T")
self.conn = sqlite3.connect('search_history.db')
try:
except Exception as e:
self.logo_image = None
self.conversation_text.configure(fg='white', bg='black')
if self.logo_image:
self.logo_label.lift()
self.predefined_queries = [
("favorite game", "I'm just a bot made by fellow students, I cannot play
games for now :),is there anything else I can help you with?"),
("what is your name", "I'm just a BetaB0T, you can call me BetaB0T!"),
("who made you", "I was developed using Python and Tkinter By Siddhant,
Hrishikesh, Dhananjay and Vijay, these are my Creators! :D")
self.conn = sqlite3.connect('search_history.db')
self.create_table()
def create_table(self):
cursor = self.conn.cursor()
self.conn.commit()
cursor = self.conn.cursor()
self.conn.commit()
def display_recent_searches(self):
recent_searches_window = tk.Toplevel(self.master)
recent_searches_window.title("Recent Searches")
recent_searches_text.pack(padx=10, pady=10)
cursor = self.conn.cursor()
rows = cursor.fetchall()
recent_searches_text.configure(state='disabled')
self.conversation_text.configure(state='normal')
self.conversation_text.configure(state='disabled')
self.conversation_text.see(tk.END)
def process_input(self):
query = self.user_input.get()
self.respond_to_query(query)
query = query.lower()
duckduckgo_answer = self.get_duckduckgo_instant_answer(query)
if duckduckgo_answer:
self.add_to_history(query, duckduckgo_answer)
else:
response_found = False
response_found = True
break
wikipedia_result = self.search_wikipedia(query)
if wikipedia_result:
self.add_to_history(query,wikipedia_result)
else:
self.logo_label.place_forget()
def clear_chat(self):
self.conversation_text.configure(state='normal')
self.conversation_text.delete('1.0', tk.END)
self.conversation_text.configure(state='disabled')
# Typing animation
self.conversation_text.configure(state='normal')
self.conversation_text.insert(tk.END, char)
self.conversation_text.configure(state='disabled')
self.conversation_text.see(tk.END)
self.master.update()
try:
url = f"https://api.duckduckgo.com/?q={query}&format=json"
response = requests.get(url)
data = response.json()
return data.get('AbstractText')
except Exception as e:
return None
try:
return result
except wikipedia.exceptions.DisambiguationError as e:
return f"There are multiple results for your query. Please be more specific.
Options are: {options}"
except wikipedia.exceptions.PageError:
def calculate_math(self):
expression = self.user_input.get()
try:
result = eval(expression)
except Exception as e:
def toggle_fullscreen(self):
self.master.attributes("-fullscreen", self.fullscreen)
def __del__(self):
self.conn.close()
def main():
root = tk.Tk()
chatbot = ChatBot(root)
root.mainloop()
if __name__ == "__main__":
main()
9. OUTPUT
ICON:
User Interface:
Predefined Query:
Query Wikpedia:
Recent Searches:
10.Testing
Unit testing serves as the foundation for a reliable system. It involves testing
individual units of code (functions, modules) in isolation to verify their correctness
and functionality. Here's how unit testing will be implemented in BetaBot's
development:
Integration testing focuses on verifying how different units of code interact and
function together as a whole. In BetaBot's context, this involves testing how
various components (e.g., user interface, information retrieval modules, math
calculation module) interact and collaborate to achieve the desired outcome.
Validation testing assesses whether the overall system meets the defined
requirements and specifications outlined for BetaBot. This testing phase bridges
the gap between the theoretical design and the actual functionality of the developed
system.
conducted where a group of users will interact with BetaBot and provide
feedback on its alignment with their expectations and needs.
Validation testing ensures that BetaBot is not only functional but also fulfills the
intended purpose and delivers value to its users.
White-box testing, also known as glass-box testing, delves into the internal
structure of the code. It involves testing specific code paths, decision points, and
internal logic to ensure they function as intended.
By examining the inner workings of the code, white-box testing helps us identify
potential logic errors or inefficiencies that might not be apparent through other
testing methods.
11.SYSTEM REQUIREMENT
10. ADVANTAGES
BetaBot, designed with user-friendliness and information retrieval at its core,
offers several advantages over existing virtual assistants:
Intuitive User Interface: BetaBot leverages a graphical user interface (GUI) that
prioritizes clarity and ease of use. This makes it accessible to users with varying
levels of technical expertise.
Open-Source Development: BetaBot's open-source nature fosters transparency
and allows for customization by the developer community. This enables ongoing
improvements and adaptation to user needs.
Focus on Privacy: By prioritizing DuckDuckGo for information retrieval, BetaBot
minimizes data collection, putting user privacy at the forefront.
Information Retrieval Process: BetaBot integrates with DuckDuckGo and
Wikipedia, providing a comprehensive information retrieval experience. Users can
access concise answers and summaries directly within the interface.
Basic Calculation Capability: BetaBot offers the ability to perform basic
mathematical calculations, eliminating the need for a separate calculator for simple
tasks.
Recent Searches: Keeps the recently searched queries with the help of Database
SQLite3
Clear Button: Clears the Screen and ends the current session.
BetaBot's user-friendly design and focus on privacy are likely to resonate with
users who prioritize these aspects in a virtual assistant. Here are some anticipated
reviews and user feedback:
"Great for quick questions! BetaBot is perfect for finding answers to simple
questions without sifting through search results." (Vaibhavi Pawar, IT Student)
"Love the privacy focus! I feel comfortable using BetaBot knowing it doesn't track
my every search." (Siddhesh Pawaskar,CS Student)
"Would love to see more features! While basic calculations are helpful, the ability
to manage tasks or integrate with other services would be amazing." (Diksha
Gupta, IT Student)
11. CONCLUSION
While the initial iteration prioritizes core functionalities, the open-source nature
fosters continuous improvement based on user feedback. Future iterations can
explore advanced features like:
12. REFERENCES
www. javapoint.com
www.geeksforgeeks.org
www.google.com
https://chat.openai.com
https://gemini.google.com/