0% found this document useful (0 votes)
29 views38 pages

Project Apna

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views38 pages

Project Apna

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

DECLARATION

I hereby declare that the project work entitled (“Cypher Chatbot”) is an

authentic record of my own work carried out at Maharaja Agrasen University

as a part of Course Curriculum for the award of the B.Tech. degree in

Computer Science & Engineering by Maharaja Agrasen Institute of

Technology, Maharaja Agrasen University, Himachal Pradesh, under the

guidance of Er. Ritika Sharma , during August to December 2024

(Signature of student)
Himanshu Sharma
(MAU21UCS039)

(Signature of student)
Timan Samal
(MAU21UCS046)

(Signature of student)
Sandeep
(MAU21UCS040)

Date: 30-11-2024

Certified that the above statement made by the student is correct to the best
of our knowledge and belief.

ER. Ritika Sharama


Faculty
Cooordinators

i
CERTIFICATE

This is to certify that the project “Cypher Chatbot in partial fulfilment of the

requirement for the award of the degree Bachelor in Computer Application by

Maharaja Agrasen Institute of Technology. Maharaja Agrasen University ,

Himachal Pradesh , is an authentic record of word carried out by group of three

members (Himanshu sharma , Timan Samal & Sandeep) under my guidance

(Signature)
Er.RitikaSharma
Faculty Coordinators

Date :

ii
ACKNOWLEDGEMENT

An idea is the first step for generation & development of anything. The initial

idea may have been of any one person, but the development & improvement on

it have always been a result of hard work, help, inspiration and blessings of

several different people. I am grateful to thank my institute Maharaja Agrasen

Institute of Technology, Baddi, for giving permission and necessary

administrative support for creating a Project. I would like to express my special

thanks of gratitude to my college faculty coordinators Er. Ranjit Kumar for their

constant support and who gave me the golden opportunity to do this wonderful

project on the topic “Cypher Chatbot”, which also helped me in doing a lot of

Research and gaining some precious knowledge. Lastly, I would like to thank

the almighty and our parents for their moral support and friends with whom we

shared our day-to-day experience and received lots of suggestions that improve

our quality of work.

iii
Abstract

This project implements an AI-driven chatbot named Cypher using Streamlit


and Google Generative AI API, designed to assist users with accurate and
concise information on health-related topics, including diseases such as
diabetes, heart diseases, and kidney diseases. The chatbot aims to provide an
intuitive, user-friendly interface for engaging with domain-specific knowledge.

The application maintains user interaction history using st.session_state,


ensuring seamless conversation continuity. A structured prompt is designed to
guide the AI's responses, enforcing rules such as brevity, organization, and
scope limitation to health and machine learning topics. The chatbot employs an
animated response mechanism, simulating real-time typing for enhanced user
experience.

The Streamlit sidebar enhances usability by providing a description of the


chatbot's capabilities, a branded avatar, and an input interface for user queries.
The integration of custom CSS further refines the app's layout and visual
appeal.

This project demonstrates how Generative AI models can be leveraged to create


specialized virtual assistants, delivering precise and well-structured information
in an interactive web application. It provides a foundation for scalable, domain-
specific chatbot solutions with applications in education, healthcare, and
beyond.

iv
v
Contents

S.No. Title Page No.

1 Introduction 1-5

2 Literature Review 6-9

3 Technologies Used 10-13

4 Theory and Methodology 14-19

5 20-21
Source Code

6 Results 22-25

7 Output 26

8 27-29
Future Scope

9 30-31
Conclusions

vi
Introduction

This project focuses on the development of Cypher, a conversational chatbot


designed to provide users with accurate and concise information about various
diseases, including their symptoms, causes, precautions, and treatments. Built
using Streamlit and Google Generative AI API, this application leverages
advanced AI models to deliver an intuitive, user-friendly interface for
interacting with domain-specific knowledge.

The primary goal of Cypher is to assist users in understanding health-related


topics and promoting awareness about diseases. It combines natural language
processing capabilities with an interactive chat interface to create a seamless
user experience. The chatbot is trained to focus on health-related queries and
respond in a structured manner, making it an efficient tool for individuals
seeking quick and reliable health information.

This project also demonstrates the integration of Generative AI with modern


web application frameworks, highlighting its potential to create domain-specific
solutions. By limiting its scope to health-related topics and machine learning,
Cypher ensures focused and relevant interactions while handling out-of-scope
queries gracefully.

The application showcases real-time chat functionality, complete with features


such as response streaming (typing animation) and session management to
maintain conversation continuity. With a sidebar for branding, navigation, and
input, the interface is designed to be both visually appealing and functional.

Maharaja Agrasen University institute of Technology Page | 1


Through this project, we aim to explore the capabilities of AI-driven chatbots in
addressing specific user needs, contributing to the growing field of intelligent
healthcare solutions.

The healthcare industry is increasingly adopting artificial intelligence (AI) to


enhance patient care, improve diagnostics, and provide reliable health
information to a wide audience. The project, Cypher – An AI-Powered
Chatbot for Health and Disease Awareness, is a practical implementation of
AI aimed at bridging the gap between users and accessible health information.
This chatbot leverages advanced natural language processing (NLP)
technologies to provide structured and accurate responses to health-related
queries in a conversational format.

This project focuses on creating a user-friendly, real-time chatbot that interacts


with users, addresses their health-related concerns, and educates them about
symptoms, causes, precautions, and treatments for various diseases. By
integrating Google Generative AI APIs and developing a robust interface with
Streamlit, this project delivers a seamless and interactive experience for users
seeking reliable health information.

Objective and Purpose

The primary objective of this project is to design and implement an AI-based


chatbot that offers accurate and concise health-related information. Unlike
generic search engines that provide unstructured data, Cypher provides tailored,
structured, and easy-to-understand information. The chatbot also maintains user
engagement through real-time interaction and supports continuity of
conversation with persistent session management.

The purpose of this project is twofold:

Maharaja Agrasen University institute of Technology Page | 2


1. Health Education: To promote awareness of diseases and preventive
measures by offering reliable and accurate information.
2. Accessibility: To create a virtual assistant that is readily accessible to
users, offering quick and clear answers without needing a healthcare
professional's direct involvement.

Features of Cypher

1. Health-Focused Assistance:
o Cypher is designed to answer questions related to diseases such as
Diabetes, Heart Diseases, Kidney Disorders, and others.
o Responses include well-structured information on symptoms,
causes, precautions, and treatments.
2. Scope Limitation for Accuracy:
o The chatbot strictly focuses on health-related topics and machine
learning queries.
o It avoids answering questions beyond its scope, ensuring
reliability.
3. Real-Time Interactivity:
o Users can experience dynamic interaction through a chat interface
that simulates typing animations for enhanced engagement.
4. Session Continuity:
o The chatbot retains conversation history during a session, offering
seamless interaction.
5. User-Centric Design:
o A visually appealing sidebar provides branding, a description of
Cypher’s capabilities, and a text input for queries.
o Custom styling is implemented for a professional and polished
look.

Maharaja Agrasen University institute of Technology Page | 3


Technical Architecture

The Cypher chatbot is built using modern technologies, ensuring performance,


scalability, and user engagement. Below are the key components of the system:

1. Streamlit:
Streamlit is used to build the web-based interface of the chatbot. Its
simplicity and interactivity allow for creating dynamic applications with
minimal code.
2. GAPI:
The core intelligence behind Cypher is powered by the Google
Generative AI model, which processes user queries and generates
contextually accurate and concise responses.
3. Backend Logic:
o The project includes embedded instructions for the AI, ensuring it
adheres to strict rules for focusing on health-related topics.
o AI responses are streamed dynamically to simulate typing
animation, enhancing the conversational experience.
4. Session Management:
The chatbot uses st.session_state to maintain chat history, ensuring that
users can continue their conversations without losing context.
5. Styling and Branding:
o Custom CSS enhances the visual design, making the application
user-friendly and professional.
o Sidebar branding and an informative section add to the chatbot’s
appeal.

Workflow

The chatbot follows a systematic process to deliver its functionality:

Maharaja Agrasen University institute of Technology Page | 4


1. User Query Input:
o Users input their health-related questions in the sidebar.
o The input is processed and enriched with specific rules for the AI.
2. AI Processing:
o The query is sent to Google Generative AI, which generates a
response based on the embedded rules and user input.
3. Response Display:
o The AI response is streamed to the user in real-time, simulating a
typing animation.
o The chatbot displays both user queries and responses in the chat
interface.
4. Session Continuity:
o All interactions are stored in session state, enabling users to
maintain a conversational flow without losing prior message

Use Cases

Cypher addresses a range of practical scenarios:

1. Health Awareness: Educating users about diseases, their symptoms, and


prevention measures.
2. Symptom Queries: Helping users identify potential health issues based
on their symptoms.
3. ML Queries: Offering guidance on machine learning-related topics as an
additional feature.

Significance of the Project

Cypher serves as a valuable tool in promoting health education and awareness.


By integrating cutting-edge AI technology with a user-friendly interface, it
empowers users to make informed decisions about their health.

Maharaja Agrasen University institute of Technology Page | 5


Literature Review
The integration of Artificial Intelligence (AI) into healthcare has become a
transformative tool in providing efficient, accessible, and accurate information.
The project described, Cypher, is an AI-powered healthcare chatbot, developed
to help users access health-related information, ranging from symptoms to
treatment options. In this literature review, we explore the evolution,
applications, and challenges of AI-based chatbots in healthcare, focusing on
relevant research and implementations.

1. AI and Chatbots in Healthcare

AI in Healthcare

Artificial Intelligence has a significant role to play in revolutionizing the


healthcare industry. By processing vast amounts of health data, AI models can
deliver insights, assist in decision-making, and provide tailored advice. Machine
learning algorithms, natural language processing (NLP), and data analysis
enable AI to understand medical terminology, predict health outcomes, and
recommend treatments.

Recent studies, such as "AI in Healthcare: Past, Present, and Future" have
demonstrated how AI can be utilized in diagnostics, risk prediction, patient
management, and drug discovery. AI's ability to process and interpret large
datasets is particularly valuable in healthcare, where accurate, timely decision-
making is critical.

Chatbots in Healthcare

Chatbots, powered by AI, have been increasingly used in healthcare for their
ability to automate and streamline communication with users. They offer
immediate and personalized responses to patient inquiries, reducing the load on
healthcare professionals while enhancing accessibility to information.

Maharaja Agrasen University institute of Technology Page | 6


In a study published by Jiang et al. (2020) titled "Artificial Intelligence in
Healthcare: Chatbots and Their Applications", it was noted that AI-powered
chatbots could effectively assist patients in providing medical advice,
scheduling appointments, reminding patients of medications, and even guiding
through symptom-checking processes.

The rise of conversational agents, such as chatbots, in healthcare settings has


been facilitated by advances in NLP and machine learning models. Google's
Gemini AI and OpenAI's GPT models have contributed to making these
chatbots more capable in understanding complex queries and providing
contextually accurate responses.

2. Cypher Chatbot's Domain-Specific Focus

The Cypher chatbot, in particular, focuses on delivering healthcare information


on specific diseases, such as diabetes, heart disease, and kidney conditions. The
specialization of chatbots in offering domain-specific knowledge has been
explored in several research papers, underlining the importance of context-
aware systems in enhancing the quality of responses.

For instance, in the study "Medical Chatbots: A Review" by Garg et al.


(2021), the authors emphasize that chatbots need to be trained with domain-
specific data to enhance the reliability of their responses. Cypher’s AI model,
embedded with explicit rules related to health information, helps ensure that the
answers are relevant, focused, and medically accurate.

A relevant use case highlighted in this study is Babylon Health, a health


assistant chatbot that uses AI to provide consultations based on personal
medical history and general medical knowledge. This chatbot helps users with
symptom checking, initial diagnostics, and even general healthcare advice,
similar to Cypher’s approach but with a more extensive healthcare domain.

3. User Interaction and Engagement

Maharaja Agrasen University institute of Technology Page | 7


The success of any AI-powered chatbot, particularly in healthcare, hinges on
user engagement and satisfaction. Providing a seamless, interactive, and
responsive user experience is key to building trust and ensuring the chatbot's
effectiveness. Cypher incorporates a streaming AI response feature, which
mimics a typing animation to create a natural conversational experience.

Studies like "User Experience and Chatbot Acceptance in Health Care" (Shah et
al., 2021) highlight that chatbots designed with engaging user interfaces and
interactive features are more likely to increase user satisfaction. The paper
emphasizes that visual elements, such as avatars, along with dynamic text
responses, can make interactions feel more human-like, fostering a sense of
trust.

Cypher’s use of an avatar, along with organized response structuring, ensures


that the user feels comfortable and engaged throughout the interaction.
Streamlit is used to create the user interface, providing a highly customizable
and interactive platform for chatbot deployment.

4. Challenges and Ethical Concerns

While AI-powered healthcare chatbots, like Cypher, offer many advantages,


there are also challenges and ethical concerns that need to be addressed. A study
by Garg et al. (2021) titled "AI in Healthcare: Current Challenges and
Future Directions" highlights several issues that AI chatbots must overcome,
including:

 Accuracy and Reliability: One of the most pressing concerns is ensuring


that the AI system provides accurate and reliable medical advice.
Incorrect or incomplete information can lead to misdiagnoses or improper
treatment.

 Data Privacy: Healthcare-related chatbots collect and process sensitive


user information. The ethical handling of this data, as well as adhering to

Maharaja Agrasen University institute of Technology Page | 8


regulations such as HIPAA (Health Insurance Portability and
Accountability Act) in the United States, is crucial.

 Bias in AI Models: AI systems are often trained on large datasets, which


may contain biases based on factors such as geography, race, or socio-
economic status. This can result in biased responses, making it essential
to continuously update and test the models for fairness.

For instance, Panch et al. (2019) in their work "The Ethical Implications of AI
in Healthcare" stressed the importance of maintaining privacy and
transparency when deploying AI-based systems, especially when they are used
to interact with vulnerable populations.

5. AI-Powered Healthcare Chatbots in Future Healthcare Systems

Looking ahead, the future of AI-powered healthcare chatbots like Cypher


appears promising. As AI technology advances, chatbots will be able to handle
more complex interactions, provide more personalized advice, and integrate
with other healthcare systems for more efficient service delivery.

The future directions are highlighted in a paper titled "Artificial Intelligence in


Healthcare: A Review" by Choudhury et al. (2020), where it is noted that the
integration of AI chatbots with electronic health records (EHRs) and wearable
health devices could lead to even more accurate on health data.

Maharaja Agrasen University institute of Technology Page | 9


Technologies Used
The Cypher chatbot is an AI-powered healthcare assistant designed to answer
user queries related to various diseases, such as diabetes, heart diseases, and
kidney diseases. Several technologies and frameworks have been employed to
build this application, ranging from natural language processing (NLP) and
generative AI models to web frameworks and APIs. Below is a detailed
overview of the technologies used in the code.

1. Google Generative AI (Gemini)

Overview:

Google’s Generative AI, particularly the Gemini model, is used for processing
natural language queries and generating responses. The Gemini API is part of
Google Cloud's AI offerings, enabling the chatbot to understand and respond to
user inputs in real-time.

Key Features:

 NLP capabilities: Gemini uses advanced NLP models to interpret and


generate human-like responses, making it ideal for building chatbots that
can handle complex user queries.

 Custom Instructions: As shown in the code, custom instructions are


provided to the model to guide its responses, ensuring that the chatbot
stays focused on providing information about diseases and their
management.

 Real-time interaction: The streaming functionality allows the AI to send


real-time responses, simulating a natural conversation, which improves
user engagement.

Maharaja Agrasen University institute of Technology Page | 10


Use in the Project:

In this project, the Gemini generative model powers the chat system, allowing
the chatbot (Cypher) to answer medical-related queries efficiently and
accurately. It handles both simple and complex requests, delivering responses
with appropriate content formatting (e.g., symptoms, causes, treatment, and
prevention).

2. Streamlit

Overview:

Streamlit is a popular open-source framework used to build interactive web


applications with Python. It simplifies the process of creating data-driven, user-
friendly web applications by offering intuitive components for visualizing data
and interacting with users.

Key Features:

 Easy Integration with Python: Streamlit allows Python-based


applications to be deployed quickly with minimal configuration. It
automatically updates the UI when the code changes, making it suitable
for rapid prototyping.

 Interactivity: Streamlit provides various components like sliders, text


inputs, and buttons, which help make the application interactive.

 Real-time Updates: The app updates dynamically as the user interacts


with it, without the need for complex frontend development.

Use in the Project:

Streamlit is used in this project to build the user interface (UI) for the Cypher
chatbot. The chatbot’s conversation interface, sidebars, and image display are

Maharaja Agrasen University institute of Technology Page | 11


all rendered using Streamlit's easy-to-use UI components. It allows users to
interact with the chatbot in a browser-based environment seamlessly.

 Text Input: Streamlit's text_input widget is used to capture user input


(queries).

 Chat Interface: The st.chat_message component is employed to show


the back-and-forth conversation between the user and the AI.

3. Python

Overview:

Python is the primary programming language used in the development of this


chatbot application. It is known for its simplicity, readability, and rich
ecosystem of libraries that facilitate machine learning, web development, and
data processing.

Key Features:

 Ease of Use: Python's clear syntax makes it accessible for developers and
accelerates the development process.

 Extensive Libraries: Python offers a wide range of libraries and


frameworks for AI and machine learning (e.g., TensorFlow, Keras,
PyTorch) and web development (e.g., Flask, Django).

 Strong Community Support: Python’s community is active and


provides a wealth of resources, tutorials, and packages to support
developers.

Use in the Project:

Python serves as the backbone of the project, integrating all the components,
including the Google Generative AI model and the Streamlit user interface. It
handles tasks such as:

Maharaja Agrasen University institute of Technology Page | 12


 Managing session states (st.session_state).

 Streaming AI responses with the time.sleep() function to simulate typing


animation.

 Integrating external APIs (such as the Google Generative AI API) to


process natural language and provide answers.

4. Google Cloud API

Overview:

The Google Cloud API provides access to Google’s powerful machine learning
services, including Generative AI models like Gemini. This API allows the
chatbot to interact with Google’s models for real-time query processing and
response generation.

Key Features:

 Scalability: Google Cloud APIs are designed to scale, handling a large


number of requests efficiently.

 AI Models: The API provides access to state-of-the-art NLP models for


tasks such as text generation, classification, and entity extraction.

 Security and Reliability: Google Cloud ensures secure, reliable access


to its models, supporting authentication through API keys.

Use in the Project:

The Google Generative AI API is configured with an API key, which enables
the Cypher chatbot to send user queries to the Gemini model. The responses
generated by the model are then displayed back to the user via the Streamlit
interface. The API key ensures secure access to the AI services, making it an
essential part of the chatbot’s functionality.

Maharaja Agrasen University institute of Technology Page | 13


Theory and Methodology
The Cypher Chatbot is an advanced artificial intelligence (AI) system
developed to engage users in health-related conversations. The chatbot
leverages state-of-the-art Generative AI technology, particularly Google’s
Gemini model, for understanding and responding to natural language queries.
The methodology is designed to ensure an interactive, real-time conversational
experience, making it easy for users to get accurate and relevant information
about various diseases, including diabetes, heart diseases, kidney diseases, and
more. This section outlines the theoretical foundation, the underlying
technologies, and the detailed methodology used to build the Cypher Chatbot.

1. Theoretical Foundation

The Cypher Chatbot is built on fundamental concepts from Natural Language


Processing (NLP), Artificial Intelligence (AI), and Human-Computer
Interaction (HCI). These principles allow the system to interact with users in a
meaningful, human-like way while delivering contextually relevant information.

1. Natural Language Processing (NLP)

Natural Language Processing (NLP) enables machines to understand and


generate human language. It involves various tasks like language modeling, text
classification, and entity recognition. For the Cypher Chatbot, NLP is central to
enabling the system to process user input, identify their intents, extract entities,
and generate coherent responses.

 Intent Recognition: The system’s ability to understand user queries, such


as recognizing when the user is asking about symptoms or treatments of a
particular disease.

Maharaja Agrasen University institute of Technology Page | 14


 Entity Extraction: The model extracts key pieces of information from
the user’s input, such as the name of a disease, symptoms, or treatments.

 Context Management: The chatbot remembers previous conversations


and utilizes that context to generate responses that make sense in the
ongoing interaction.

2. Generative AI Models

Generative AI refers to algorithms that generate new content based on input


data. The Cypher Chatbot employs Google’s Gemini, a generative AI model, to
produce responses to user queries.

 Transformer Models: At the core of Gemini lies the transformer


architecture, which allows the model to efficiently handle long-term
dependencies in text. Unlike traditional models, transformers process all
words in a sentence simultaneously, improving efficiency and accuracy.

 Pretrained Models: The Gemini model is pretrained on vast amounts of


text, allowing it to understand complex queries and generate contextually
relevant answers.

 Fine-tuning: For the specific purpose of answering health-related


questions, the model can be fine-tuned using medical datasets, allowing it
to specialize in topics such as diseases, symptoms, causes, and
treatments.

3. Human-Computer Interaction (HCI)

Human-Computer Interaction (HCI) is essential for ensuring that the chatbot is


user-friendly and responsive. In this project, the chatbot's user interface is
designed with a focus on simplicity and clarity. The goal is to make it easy for
users to interact with the system without feeling overwhelmed by complex
inputs or technical jargon.

Maharaja Agrasen University institute of Technology Page | 15


 Interactive Design: The chatbot interface is built using Streamlit, which
enables rapid prototyping of web applications. It provides an intuitive
way to display user inputs and AI-generated responses.

 Engaging User Experience: By using streaming responses (where the


AI's response appears word by word), the system mimics a natural
conversation, increasing user engagement.

 Personalization: The chatbot can be personalized to a certain extent by


adjusting its behavior based on user queries, allowing it to respond in a
more tailored manner.

2. Methodology

The methodology for developing the Cypher Chatbot follows an iterative


approach, focusing on both the backend (AI) and frontend (user interface). The
project integrates these components to deliver an efficient, interactive chatbot
system.

1. System Architecture and Design

The system is divided into two primary components: the Backend (AI Model)
and the Frontend (User Interface). These components communicate through a
client-server architecture, ensuring smooth interactions between the user and the
AI system.

2. Backend (AI Model Integration)

The backend is the heart of the Cypher Chatbot, where all the AI-related
processing happens.

 Google Generative AI Model (Gemini): This is the main model


responsible for understanding and generating responses to user queries.
The chatbot communicates with the model via the Google Cloud API.

Maharaja Agrasen University institute of Technology Page | 16


 Session Management: The backend uses session variables to track the
user’s interactions, ensuring that the conversation history is maintained.
These variables store both the user’s messages and the chatbot’s
responses, which are critical for context awareness.

 Query Formatting: When the user enters a query, it is first formatted


into a structured request that includes pre-defined instructions for the AI
model. These instructions help guide the model’s behavior, ensuring it
focuses on health-related topics and provides responses according to the
specified format.

3. Frontend (Streamlit Web Interface)

The frontend is where the user interacts with the system. Streamlit is used to
build the web interface, making it easy to create and deploy the chatbot on the
web.

 User Input: Users enter queries into a text box located in the sidebar of
the web application. These inputs are then processed by the backend AI
model.

 Response Display: The AI’s responses are displayed in a chat message


container. Each message is shown in sequence, ensuring that the
conversation flows smoothly.

 Real-time Response Streaming: One of the standout features of the


Cypher Chatbot is the real-time response streaming. This is achieved
using the stream=True parameter when sending queries to the backend.
Instead of displaying the response all at once, the system streams the
output word by word, with a slight delay between each word to simulate
typing. This technique mimics human conversation, making the chatbot
feel more lifelike.

Maharaja Agrasen University institute of Technology Page | 17


4. Data Flow and Interaction

The methodology revolves around efficient data flow between the user interface
and the backend AI system. The process is broken down into the following
steps:

1. User Input: The user enters a query into the input box in the sidebar. The
query is typically related to diseases, symptoms, treatment, or prevention.

2. Message Handling: The input message is processed by the backend AI


system. The query is reformatted into a structured prompt, which includes
custom instructions for the AI model.

3. AI Processing: The backend sends the query to the Google Generative


AI Model, where it generates a response based on its training. The
model's output is then streamed back to the frontend.

4. Response Display: The response is displayed word by word, giving the


impression of a real-time conversation. The response contains structured
information, such as symptoms, causes, and treatments.

5. Session Update: Both the user’s query and the assistant's response are
stored in session variables to maintain context between multiple queries.

5. Real-time Response Streaming

A key feature of the chatbot is real-time response streaming, which enhances


the user experience by displaying the AI’s responses progressively, rather than
all at once. This is achieved through the following steps:

1. Incremental Output: As the AI model generates its response, it is sent


back in increments (chunks). Each chunk consists of a part of the
complete response.

Maharaja Agrasen University institute of Technology Page | 18


2. Word-by-Word Display: The response is split into words, and each
word is displayed with a slight delay, creating the effect of the assistant
typing.

3. User Engagement: The streaming approach ensures that users are


engaged and interested throughout the interaction. The typing animation
effect simulates a more conversational and interactive experience.

6. User-Centric Design

The Cypher Chatbot is designed with usability in mind, ensuring that the user
can interact with the system intuitively.

 Minimalistic Interface: The chat interface focuses on simplicity,


displaying only the essential elements, such as the chat input and message
display areas.

 Clear Instructions: The sidebar provides users with information about


the chatbot's purpose and capabilities, helping them understand the scope
of the chatbot’s knowledge.

 Focused Scope: The chatbot is designed to handle questions only about


health-related topics. If the user asks a question outside of this domain,
the chatbot responds by stating that it can only answer questions related
to diseases.

7. Session Management and History Tracking

To maintain context and coherence in the conversation, the Cypher Chatbot


employs session management. This involves storing both user inputs and
assistant responses in session variables. These variables are updated after every
interaction and used to track the ongoing conversation. This ensures that the
chatbot can provide relevant responses based on the entire conversation history.

Maharaja Agrasen University institute of Technology Page | 19


Source Code

Maharaja Agrasen University institute of Technology Page | 20


Maharaja Agrasen University institute of Technology Page | 21
Results
The Cypher Chatbot is designed to provide users with accurate and informative
responses about various health-related topics, including symptoms, causes,
treatments, and prevention strategies for diseases such as diabetes, heart
diseases, and kidney diseases. The results of the project demonstrate its
effectiveness in providing real-time, interactive responses and offering a user-
friendly experience. Below are the key outcomes and results observed after the
implementation of the system:

1. Functional Chat Interface

Maharaja Agrasen University institute of Technology Page | 22


The system successfully implements a chat-based interface that allows users to
interact with the chatbot seamlessly. The following features of the chat interface
contribute to its success:

 User-Friendly Design: The use of Streamlit provides a minimalist


interface that is easy to navigate. The sidebar displays a clear input field
where users can type their queries, and the chatbot’s responses are
displayed in a conversation-style chat window.
 Interactive Responses: The chatbot responds to user queries in real-time.
The streaming response feature ensures that answers are typed out word
by word, which mimics the natural flow of human conversation. This
increases user engagement and creates an immersive experience.
 Context Awareness: The chatbot retains the context of previous
interactions, ensuring that the AI can provide relevant answers even in
ongoing conversations. The chat history is maintained in session
variables, which helps track the user’s questions and the AI's responses.

2. Accurate and Relevant AI Responses

One of the core goals of the project was to ensure that the AI provides accurate,
relevant, and well-organized information related to health. The results indicate
that the Google Gemini Generative AI model effectively meets this goal:

 Correct Health Information: The chatbot answers user questions


regarding diseases, their symptoms, causes, treatments, and precautions.
For instance, if a user inquires about the symptoms of diabetes, the
chatbot provides a concise yet accurate list of symptoms like frequent
urination, excessive thirst, and blurred vision.

Maharaja Agrasen University institute of Technology Page | 23


 Well-Organized Answers: The AI ensures that the responses are
structured, particularly when the question involves medical details. The
answer is presented in an organized manner, breaking down information
into categories like symptoms, causes, prevention, and treatment options.
This ensures clarity for the user.
 Scope Limitation: The chatbot only answers queries related to health
topics. If the user asks a question outside the specified domain (e.g.,
unrelated to health or diseases), the chatbot responds with a message
indicating that it can only provide answers on health topics. This
approach helps maintain focus and prevents the system from generating
irrelevant responses.
 Brief Responses: The chatbot’s responses are generally concise,
following the instruction that answers should be brief unless the user
requests a detailed explanation. This ensures that users get quick answers
but can ask for further details if necessary.

3. Real-Time Streaming of Responses

A key feature of the Cypher Chatbot is the streaming response mechanism,


where the AI’s response is typed out progressively, simulating a natural
conversation. This aspect of the system leads to the following outcomes:

 User Engagement: The streaming effect ensures that the user remains
engaged throughout the interaction. The response appears word-by-word,
which creates a sense of real-time interaction. The user is more likely to
stay interested, as the experience feels conversational and dynamic.

Maharaja Agrasen University institute of Technology Page | 24


 Typing Animation: The slight delay between each word in the response
helps mimic the human typing speed, providing a sense of authenticity to
the conversation. The user sees the chatbot "thinking" and "typing,"
which adds to the experience.
 Smooth Conversation Flow: The word-by-word streaming helps keep
the conversation flowing smoothly. The users feel like they are having a
live conversation with the assistant rather than receiving a block of text
all at once.

4. Session Management and History Tracking

The chatbot utilizes session management to ensure continuity and coherence in


conversation. The following results were observed from the session
management system:

 Conversation Continuity: Session variables are used to track the


conversation history, ensuring that the AI is aware of the context of the
conversation. For example, if a user asks multiple questions about
diabetes, the AI remembers previous responses and provides contextually
relevant answers.
 Message Storage: Both user queries and AI responses are stored in
session variables. This allows the system to reference past interactions
and ensure that the chatbot responds based on the entire conversation
history.
 Handling Multiple Interactions: The chatbot performs well when
handling multiple interactions. Even when the user asks complex or
follow-up questions, the system is able to provide coherent responses
based on the accumulated history.

5. User Satisfaction and Feedback

Maharaja Agrasen University institute of Technology Page | 25


Although direct user feedback is beyond the scope of this implementation (as it
would require additional user testing), preliminary observations from the
chatbot’s design indicate that the system is likely to provide a satisfying user
experience. Here’s why:

 Clear and Concise Answers: The chatbot adheres to the principle of


providing brief and to-the-point answers, which is valuable for users who
want quick information.
 Efficient Information Retrieval: The use of Generative AI allows the
chatbot to pull information from a vast knowledge base, ensuring the
accuracy of responses. This is particularly beneficial for users seeking
information about health topics they may not be familiar with.
 Engagement Through Interactive Chat: The real-time response feature
increases user engagement, as the chatbot feels like an active participant
in the conversation, not just a tool providing static answers.

Output

Maharaja Agrasen University institute of Technology Page | 26


Future Scope

Maharaja Agrasen University institute of Technology Page | 27


The Cypher Chatbot project has shown promising results in terms of
delivering health-related information effectively and interactively. However,
there are various areas where the system can be improved and expanded to offer
enhanced functionality and greater user satisfaction. The following points
outline the potential future scope and development of this chatbot system:

1. Expansion of Knowledge Domains

Currently, the Cypher Chatbot focuses on providing answers related to health


and diseases. The scope can be significantly expanded by incorporating
additional knowledge domains, such as:

 General Knowledge: The chatbot could be enhanced to answer questions


in broader categories, such as history, science, technology, and
geography. This would make it a more versatile assistant, capable of
addressing a wider range of user queries.
 Mental Health Assistance: Given the increasing importance of mental
health, the chatbot could be enhanced to provide mental health support,
including answering questions related to stress, anxiety, depression, and
general wellness.
 Diet and Nutrition: Adding a nutrition-focused knowledge base would
allow users to ask questions about healthy eating, diets, and nutrition
management, particularly in relation to chronic diseases like diabetes and
heart conditions.

2. Improved Personalization and User Profiling

Maharaja Agrasen University institute of Technology Page | 28


To increase the chatbot’s effectiveness and user engagement, personalized
interactions can be introduced. For example:

 User Profiles: The chatbot could maintain personalized profiles for


individual users, storing basic information such as age, medical history,
and preferences. This would allow the assistant to tailor its responses
based on the user’s specific health context, making the information more
relevant and targeted.
 Personalized Health Recommendations: By analyzing user inputs and
responses, the chatbot could offer more personalized advice, such as
recommending lifestyle changes, dietary adjustments, or specific
preventive measures based on the user’s health conditions.
 Health Monitoring Integration: The chatbot could be connected to
wearable devices or health apps to track the user’s health metrics (e.g.,
heart rate, blood sugar levels) and offer real-time advice based on that
data.

3. Enhanced Conversational Abilities

While the chatbot performs well in structured conversations, there is room for
improvement in handling more complex, free-form interactions. Future versions
could incorporate the following enhancements:

 Natural Language Processing (NLP) Improvements: The chatbot


could benefit from more advanced NLP techniques, such as sentiment
analysis, contextual understanding, and the ability to handle ambiguous
or vague queries. This would allow the chatbot to respond more
effectively to users with diverse speech patterns and complex queries.
 Multilingual Support: As the chatbot is currently tailored for English-
language users, adding multilingual support would make it more

Maharaja Agrasen University institute of Technology Page | 29


accessible to a global audience. Supporting languages such as Spanish,
French, Hindi, and Mandarin would increase its usability in different
regions and for people with varying linguistic backgrounds.
 Emotion Detection and Empathy: Integrating sentiment analysis to
detect the user's emotional state (e.g., frustration, confusion, or urgency)
could help the chatbot respond with more empathy. This feature would be
particularly useful in health-related queries where the user might be
anxious or worried.

Maharaja Agrasen University institute of Technology Page | 30


Conclusions
 Purpose of the Code:

 The code implements a Streamlit-based chatbot application named


Cypher. It integrates Google's Generative AI (Gemini) to provide health-
related guidance, focusing on diseases like Diabetes, Heart Diseases, and
Kidney Diseases.

 Core Features:

 Health-specific Expertise: The chatbot is designed to answer health-


related questions about symptoms, causes, precautions, and medications
in an organized manner.
 Boundary Enforcement: It explicitly avoids discussing non-health-
related topics, redirecting such queries to Machine Learning-related
topics.
 Typing Animation: The chatbot simulates human-like typing using
response streaming.

 Strengths:

 Session Management: The use of st.session_state ensures


persistent conversation history and session data across app reruns.
 Customizable Rules: Rules for responses (e.g., maintaining the name
"Cypher" and not revealing Gemini origins) are enforced via the input
query.
 Interactive UI: The sidebar integrates branding (an image) and provides
a clear purpose description for Cypher.

 Issues and Weaknesses:

Maharaja Agrasen University institute of Technology Page | 31


 API Key Security Risk: The hardcoding of the API key is a major
security vulnerability. This should be replaced with environment
variables or a secure method of storage.
 Incomplete Input Handling: User input is not fully cleared after
submission, causing potential clutter or errors.
 Limited Error Handling: The code lacks robust error handling for API
failures, invalid inputs, or missing session states.
 Unoptimized Animation: The character-by-character typing animation
can be slow for longer responses, potentially frustrating users.

 Improvements Recommended:

 Security Enhancements: Replace hardcoded API keys with secure


environment variables using libraries like dotenv.
 Error Handling: Implement error-catching mechanisms to manage API
issues, invalid inputs, or connection problems gracefully.
 Performance Tuning: Dynamically adjust typing animation speed based
on response length for a smoother user experience.
 Code Cleanup: Remove unused variables and organize logic for better
readability and maintainability.

 Reusability and Maintenance:

 The code is modular and straightforward, making it relatively easy to


extend or modify. With minor adjustments, it could support additional
topics or integrate more advanced UI features.

 Alignment with Project Goals:

 For your Baymax Healthbot project, this implementation aligns well


with the goals of providing structured health guidance. supp

Maharaja Agrasen University institute of Technology Page | 32

You might also like