Sem 6 Final Version)
Sem 6 Final Version)
ON
submitted by
of
Bachelor of Science
in
Computer Science
Under the guidance of
Prof. THIRU MENAGA PRABHU NADAR
Department of Computer Science
Mahendra Pratap Sharada Prasad Singh College of Arts, Commerce and Science
(SEM VI)
(2024 - 2025)
CERTIFICATE
The report titled
Bachelor of Science
in
Computer Science
from
PLACE:
DATE:
ACKNOWLEDGEMENT
No project is ever complete without the guidance of those experts who have previously walked this
path and mastered it, becoming mentors in the process. I would like to take this opportunity to thank
all the individuals who helped me in bringing this project to life.
I am thankful to my college for providing excellent facilities that helped me complete and present
this project.
I express my deepest gratitude to my project guide for their valuable and timely advice during the
various phases of the project. I am also grateful for the facilities, support, and patience they provided,
along with their trust in my abilities and the flexibility they offered in terms of working and reporting
schedules.
INDEX
1 Introduction 2
1.1 Overview of the Project
1.2 Purpose and Objectives
1.3 Problem Statement
2 Advantages and Disadvantages 4
2.1 Key Benefits of the System
2.2 Limitations and Challenges
3 Scope of the Project 6
3.1 Scope of Implementation
3.2 Future Enhancements
4 Features 10
4.1 Major Functionalities
4.2 User Interface and Experience
5 Feasibility Study 12
5.1 Technical Feasibility
5.2 Operational Feasibility
5.3 Economic Feasibility
6 System Analysis 15
6.1 Existing System
6.2 Proposed System
7 System Design 17
7.1 ER
7.2 Database ER
8 Project Coding 19
8.1 Code Implementation
8.2 Explanation of Key Algorithms
and Functions
9 Project Output Screens 36
9.1 Screenshots
10 Hardware and Software 46
Requirements
10.1Minimum and Recommended
Hardware Specifications
10.2Software Tools and Platforms
Used
11 Conclusion 48
11.1Summary of the Project
12 Bibliography 50
12.1List of References
ABSTRACT
Artificial intelligence has revolutionized digital interactions, making chatbots essential for
automating conversations, delivering information, and enhancing user engagement. This project
introduces an AI-powered chatbot that leverages the DeepSeek LLM to generate concise, engaging,
and humor-infused responses, creating a dynamic and enjoyable user experience. The chatbot
integrates authentication, session management, and message storage, allowing users to maintain
continuous and personalized conversations.
Built using Streamlit, the chatbot offers a clean and intuitive user interface, ensuring accessibility for
both technical and non-technical users. The core language model integration is powered by Hugging
Face, enabling seamless connectivity with DeepSeek for intelligent response generation. To
efficiently manage user data, Astra DB (NoSQL) is used, ensuring fast, scalable, and reliable storage
for chat histories and user sessions. This architecture enables smooth, real-time interactions while
preserving context across different sessions.
A key challenge addressed in this project is server congestion in DeepSeek LLM, which can lead to
delays or unavailability. To mitigate this, the chatbot features a fallback mechanism, ensuring
uninterrupted usability even during high traffic. Future improvements may include integrating
alternative LLMs, implementing local model hosting, or leveraging caching techniques to enhance
response speed and reliability.
This project highlights the potential of large language models in creating intelligent and engaging
chatbots. By incorporating secure authentication, session persistence, and scalable database
management, it delivers an efficient, responsive, and enjoyable conversational experience, making
AI-driven interactions more accessible and reliable for users.
1
1. INTRODUCTION
1.1Overview of the Project -
Artificial Intelligence (AI) has revolutionized human-computer interactions, with chatbots playing a
key role in automating conversations, assisting users, and delivering personalized responses. This
project introduces an AI-powered chatbot leveraging DeepSeek LLM to generate concise,
engaging, and humor-infused responses, making AI interactions more enjoyable and dynamic.
Unlike traditional chatbots that often produce generic replies, this chatbot is designed to create an
interactive and entertaining user experience.
The chatbot incorporates secure authentication, session management, and message storage,
ensuring users can maintain conversation context across sessions. It features a user-friendly
interface built with Streamlit, making it accessible to both technical and non-technical users. The
chatbot seamlessly integrates with Hugging Face for DeepSeek LLM connectivity, while Astra DB
(NoSQL) serves as an efficient online database for storing user sessions and chat histories.
One of the major challenges of utilizing DeepSeek LLM is server congestion, which can cause
response delays or unavailability. This project addresses this issue by implementing strategies to
enhance chatbot usability even when DeepSeek’s servers are overloaded. Future improvements may
include fallback mechanisms, model switching, or local LLM hosting to improve reliability and
reduce dependency on external servers.
The primary goal of this project is to develop an intelligent and engaging AI chatbot that provides
users with quick, interactive, and context-aware responses while ensuring a smooth and
uninterrupted experience.
● Develop an AI chatbot using DeepSeek LLM for generating natural and engaging
2
conversations.
● Ensure a seamless user experience through authentication and session persistence.
● Implement a scalable database using Astra DB (NoSQL) for efficient chat history storage.
● Design a user-friendly interface with Streamlit for easy and intuitive interaction.
● Address server congestion issues by implementing fallback mechanisms or alternative
strategies to ensure chatbot availability.
● Explore future enhancements, such as integrating multiple LLMs or deploying a local/offline
model for improved reliability.
Traditional chatbots often produce generic, repetitive, and unengaging responses, leading to a poor
user experience. While large language models like DeepSeek LLM offer advanced conversational
capabilities, they frequently face server congestion, resulting in delayed or unavailable responses.
By addressing these limitations, this project contributes to building a more engaging, scalable, and
efficient AI-powered chatbot, enhancing user interaction while minimizing disruptions caused by
external dependencies.
3
2. Advantages and Disadvantages
● Dependency on External AI Models – Since the chatbot relies on DeepSeek LLM, its
performance is subject to external server availability, which may cause delays or failed
responses during outages.
● Lack of Offline Functionality – The chatbot currently does not support local inference,
meaning an internet connection is required for interaction.
4
● Limited Humor Moderation – While designed for entertainment, AI-generated humor
may sometimes be misinterpreted or inappropriate, necessitating manual moderation
and refinement.
● Scalability Costs – Cloud-based storage and API calls may incur additional costs as user
traffic grows, requiring efficient resource management to optimize expenses.
● Latency Issues During Peak Traffic – If DeepSeek’s servers are under high demand,
response times may increase, temporarily affecting the user experience.
5
3. Scope of the Project
The AI-powered chatbot is designed to provide users with humorous, engaging, and context-aware
conversations using DeepSeek LLM. The system integrates with Hugging Face for AI interaction,
Astra DB for cloud-based chat storage, and Streamlit for a simple yet functional UI. It also includes
authentication and session management to enhance user experience.
● User Authentication & Session Management – Users can sign up, log in, and maintain
persistent sessions to access past conversations.
● AI-Powered Conversational Experience – The chatbot generates short, humorous, and
engaging responses using DeepSeek LLM to keep interactions fun and interactive.
● Handling AI Model Downtime & Server Overload – Designed to mitigate delays and
server overload by implementing fallback mechanisms.
● Cloud-Based Storage & Data Management – Chat history, user data, and session logs are
stored using Astra DB, ensuring seamless retrieval for future interactions.
● Minimalist & User-Friendly Interface – A Streamlit-based UI makes the chatbot
accessible, even for non-technical users.
● Integration with Hugging Face API – The chatbot accesses DeepSeek LLM via Hugging
Face, making it adaptable to future AI model upgrades.
● Scalability & Performance Optimization – The system is cloud-based and scalable,
allowing future expansion for more users, additional AI models, and improved response
times.
Scope of Implementation:
6
1.2.2. Chat window for real-time AI interactions.
1.2.3. Session tracking to allow users to continue conversations seamlessly.
2. Backend: AI Processing & Response Generation
2.1. DeepSeek LLM (via Hugging Face API) – Generates engaging and humorous
responses to user queries.
2.2. Session Management System – Ensures users can resume previous chats without
losing data.
2.3. Handling Server Load – Implements fallback strategies to manage DeepSeek
server overload.
3. Database: Astra DB for Storage
3.1. Purpose: Stores chat history, user authentication details, and session logs for data
retrieval.
3.2. Features:
3.2.1. NoSQL-based storage ensures high scalability.
3.2.2. Fast and efficient data retrieval for personalization.
4. Deployment & Hosting
4.1. Cloud-Based Deployment – Ensures 24/7 accessibility from anywhere.
Hugging Face API Integration – Allows seamless AI model updates and
enhancements
4.2. Optimized API Call Management – Reduces latency and enhances response
times.
To improve efficiency, scalability, and user experience, the following enhancements are planned for
future updates:
● The chatbot currently depends on DeepSeek LLM, which may cause delays due to server
congestion.
● Future updates will integrate multiple AI models (e.g., LLaMA, GPT, Mistral AI) to
switch dynamically based on performance and availability.
7
2. AI Fine-Tuning & Personalization
● User-Based Humor Preferences – The chatbot will adapt its tone, style, and response
length based on past user interactions.
● Enhanced AI Training – Fine-tuning DeepSeek LLM to improve accuracy, humor quality,
and contextual awareness.
● Instead of relying solely on external APIs, a locally hosted AI model will be introduced for
offline functionality.
● Benefits:
○ Eliminates server dependency.
○ Faster response times.
○ Greater data privacy.
4. Advanced UI Features
● Speech-to-Text Input – Users can talk instead of typing for a more natural interaction.
● AI-Generated Voice Responses – The chatbot will speak its replies to create an immersive
conversational experience.
● Third-Party API Access – Developers can integrate the chatbot into their applications.
● Premium AI Plans – Users can subscribe to faster response plans with additional
8
customization options.
9
4. Features
11
5. Feasibility Study
● AI Model Integration
○ The project utilizes DeepSeek LLM via Hugging Face, which provides
state-of-the-art AI responses.
○ Potential challenges: DeepSeek's busy servers may cause delays or failures in
generating responses.
○ Solution: Future versions may integrate alternative fallback AI models to
maintain uninterrupted service.
● Backend and Database Selection
○ The chatbot uses Astra DB (NoSQL) for storing user data, chat history, and
session details.
○ NoSQL databases are chosen because they provide:
■ High scalability and fast read/write operations.
■ Flexible data structure that allows easy modifications.
● API & Cloud Integration
○ The chatbot integrates Hugging Face APIs to fetch responses from DeepSeek
LLM.
○ Challenges:
■ API latency may affect response times.
■ Cloud costs may increase with high API usage.
○ Solution: Implementing caching mechanisms for frequently asked queries to
reduce API calls.
● Development Tools & Frameworks
○ Streamlit: Used for creating a simple and responsive UI for the chatbot.
○ Python: The primary programming language for backend development.
○ Database Connector (for authentication): Used to manage user login credentials
securely.
○ Astra DB (NoSQL): Used for efficient data storage.
● Deployment & Scalability
12
○ The chatbot can be deployed on cloud platforms such as AWS, Google Cloud, or
Hugging Face Spaces.
○ The system is scalable, allowing future improvements like multi-model AI
switching when DeepSeek is unavailable.
13
5.3. Economic Feasibility
● Development Costs
○ Technology Stack:
■ DeepSeek LLM via Hugging Face (Free-tier available, but may require a
paid plan for high usage).
■ Astra DB (NoSQL) – Free tier available but may incur costs with heavy
usage.
■ Streamlit (Free for local use, paid options for cloud deployment).
■ Cloud Hosting (AWS/GCP) (Optional for scaling).
○ Estimated Initial Costs: Low, as free tiers cover most development needs.
● API Costs
○ Hugging Face APIs might incur costs based on usage limits.
○ Solution: Implement rate-limiting and caching to minimize API calls.
● Deployment & Maintenance Costs
○ If deployed on cloud servers, monthly costs depend on traffic and storage
requirements.
○ Solution: Optimize database queries and storage usage to reduce costs.
● Potential Revenue Models
○ Freemium Model:
■ Free users get a limited number of interactions per day.
■ Premium users get unlimited access and extra features.
○ API Integration for Businesses:
■ Offer chatbot integration as a service for customer support.
○ Advertisements:
■ Display non-intrusive ads in the UI for revenue generation.
14
6. System Analysis
The current landscape of AI chatbots consists of various models and platforms. However, they
come with certain limitations that impact their usability.
15
○ Developed using Streamlit, ensuring a clean and interactive UI.
○ The chatbot responds in a funny and engaging tone, making interactions more
enjoyable.
● Authentication & Security
○ Uses a secure login system to ensure that each user has a private session.
○ Prevents unauthorized access and protects chat history.
● Optimized API Calls to Reduce Costs
○ Implements response caching to reduce unnecessary API requests.
○ Reduces operational costs while maintaining fast responses.
16
7. System Design
7.1. ER Diagram -
17
7.2. Database ER Diagram -
18
8.Project Coding
Initialization
import streamlit as st
from huggingface_hub import InferenceClient
import random
from astrapy.db import AstraDB
import uuid
from datetime import datetime
import hashlib
import requests
# Constants
👤"
USER_AVATAR = "
BOT_AVATAR = "🤖"
def get_or_create_collection(name):
collections = db.get_collections()['status']['collections']
return db.create_collection(name) if name not in collections else db.collection(name)
19
return (
get_or_create_collection("users"),
get_or_create_collection("chat_sessions"),
get_or_create_collection("messages"),
InferenceClient(api_key=HUGGINGFACE_API_KEY)
)
user_data = user['data']['document']
if user_data['password'] != hashed_password:
st.error("Incorrect password. Please try again.")
return None
return user_data['username']
21
except Exception as e:
st.error(f"Incorrect email. Please try again.")
return None
def check_email(email):
try:
user = users_collection.find_one({"email": email})
return False
except Exception as e:
print(f"Error checking email: {str(e)}")
st.error(f"Error checking email: {str(e)}")
return False
define otpEmail(email):
url = "https://send-bulk-emails.p.rapidapi.com/api/send/otp/mail"
22
payload = {
"subject": "Password Recovery OTP",
"from": "[email protected]",
"to": f"{email}",
"senders_name": "EKKO AI",
"body": f"Your OTP is {otp}"
}
headers = {
"x-rapidapi-key": "e448bfa06emsh9053d11a8be63ddp188ae7jsnf440b6eadba1",
"x-rapidapi-host": "send-bulk-emails.p.rapidapi.com",
"Content-Type": "application/json"
}
try:
response = requests.post(url, json=payload, headers=headers)
data = response.json()
if response.status_code == 200:
return otp
else:
st.error(f"Failed to send OTP: {data.get('message', 'Unknown error')}")
return None
except Exception as e:
st.error(f"Failed to send OTP: {str(e)}")
return None
def get_user_sessions(email):
if not email:
return []
response = sessions_collection.find({'email': email})
return [{
'_id': doc['_id'],
'session_name': doc['session_name'],
'created_at': doc.get('created_at', '')
} for doc in response['data']['documents']]
def get_session_messages(session_id):
response = messages_collection.find({"session_id": session_id})
return sorted(response['data']['documents'], key=lambda x: x['timestamp'])
# AI Query Function
def query_huggingface(context, question):
24
try:
messages = [
{"role": "system", "content": "You are a funny and friendly AI and the most important thing
is you should answer in short and concise manner not giving long answers. Be honest, funny, and
slightly cursed."},
{"role": "user", "content": f"Context: {context}\nQuestion: {question}"}
]
completion = client.chat.completions.create(
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
messages=messages,
max_tokens=1000
)
return final_answer
except Exception as e:
st.error(f"Error: {e}")
return "Sorry, I'm having trouble thinking right now. My brain cells are on strike! Please try
again."
def render_sidebar():
st.title("EKKO AI")
if st.button("New Chat"):
handle_new_chat()
if st.session_state.current_session_id:
if st.session_state.editing_session_name:
new_name = st.text_input("Rename session:", value=st.session_state.current_session,
key="session_rename_input")
if st.button("Save", key="save_edit_btn"):
sessions_collection.update_one({"_id": st.session_state.current_session_id}, {"$set":
{"session_name": new_name}})
st.session_state.current_session = new_name
st.session_state.editing_session_name = False
st.rerun()
if st.button("Cancel", key="cancel_edit_btn"):
st.session_state.editing_session_name = False
st.rerun()
else:
col1, col2 = st.columns([4, 1])
with col1:
st.markdown(f"**{st.session_state.current_session}**")
with col2:
if st.button(" ✏️"):
st.session_state.editing_session_name = True
st.rerun()
sessions = get_user_sessions(st.session_state.user_email)
if sessions:
st.markdown("#### History:")
26
for session in sessions:
if st.button(f" {session['session_name']}", key=f"session_{session['_id']}"):
st.session_state.current_session_id = session['_id']
st.session_state.current_session = session['session_name']
st.session_state.messages = [
{"role": msg['role'], "content": msg['content']}
for msg in get_session_messages(session['_id'])
]
st.rerun()
st.markdown("---")
if st.button("Logout"):
reset_session_state()
st.caption(" 🚀 Powered by EKKO | © 2025")
def render_main_content():
initialize_session_state()
with st.columns([6,1])[1]:
render_user_profile()
display_chat_history()
handle_user_input()
def render_user_profile():
st.write(f"Welcome {st.session_state.username}!")
def display_chat_history():
initialize_session_state()
if not st.session_state.messages:
st.info(" 💬 Start a new conversation!")
else:
for message in st.session_state.messages:
with st.chat_message("user" if message['role'] == 'user' else "assistant",
avatar=USER_AVATAR if message['role'] == 'user' else BOT_AVATAR):
st.markdown(message['content'])
27
def handle_user_input():
if not st.session_state.current_session_id:
new_session_id = save_session(st.session_state.user_email, f"Chat
{len(get_user_sessions(st.session_state.user_email)) + 1}")
st.session_state.current_session_id = new_session_id
st.session_state.current_session = f"Chat {len(get_user_sessions(st.session_state.user_email))}"
st.session_state.messages.extend([
{"role": "user", "content": user_input},
{"role": "assistant", "content": response}
])
message_placeholder.markdown(response)
except Exception as e:
message_placeholder.error(f"Sorry, something went wrong! {str(e)}")
def reset_session_state():
28
for key in list(st.session_state.keys()):
del st.session_state[key]
initialize_session_state()
def handle_new_chat():
if st.session_state.current_session_id and st.session_state.messages:
sessions_collection.update_one(
{"_id": st.session_state.current_session_id},
{"$set": {"session_name": st.session_state.current_session}}
)
st.session_state.update({
"messages": [],
"context": "",
"current_session_id": None,
"current_session": None,
"last_input": ""
})
st.rerun()
def render_login_page():
st.title("Login")
email = st.text_input("Email")
29
password = st.text_input("Password", type="password")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Login"):
if username := verify_user(email, password):
st.session_state.update(authenticated=True, user_email=email, username=username)
st.rerun()
with col2:
if st.button("Go to Signup"):
st.session_state.show_signup = True
st.rerun()
with col3:
if st.button("Forget Password"):
st.session_state.render_OTP = True
st.rerun()
def render_otp_page():
st.title("Forget Password")
st.subheader("Enter your email to reset password")
# Email input
forgetEmail = st.text_input("Email", value=st.session_state.forgetEmail or "")
if not email_exists:
st.error("Email not found. Please enter a registered email address.")
return
31
col1, col2 = st.columns(2)
with col1:
if st.button("Verify OTP"):
if not otp:
st.error("Please enter the OTP.")
elif otp == str(st.session_state.otp_verify):
st.success("OTP verified successfully!")
# Set state to show password reset form
st.session_state.render_forget_password = True
st.session_state.render_OTP = False
st.rerun()
else:
st.error("Invalid OTP. Please try again.")
with col2:
if st.button("Resend OTP"):
new_otp = otpEmail(st.session_state.forgetEmail)
if new_otp:
st.session_state.otp_verify = new_otp
st.success("New OTP sent successfully!")
else:
st.error("Failed to resend OTP. Please try again.")
32
def render_forget_password_page():
st.title("Reset Password")
if not st.session_state.forgetEmail:
st.error("Email verification required. Please go back and verify your email.")
if st.button("Go Back to Email Verification"):
st.session_state.render_forget_password = False
st.session_state.render_OTP = True
st.rerun()
return
if st.button("Reset Password"):
if not newPassword or not newConfirmPassword:
st.error("All fields are required.")
return
if len(newPassword) < 6:
st.error("Password must be at least 6 characters long.")
return
if newPassword != newConfirmPassword:
st.error("Passwords do not match.")
return
try:
if new_password(st.session_state.forgetEmail, newPassword):
st.success("Password reset successfully!")
if st.button("Back to Login"):
# Reset all OTP-related state
st.session_state.render_forget_password = False
st.session_state.forgetEmail = None
st.session_state.otp_sent = False
st.session_state.otp_verify = None
st.rerun()
def render_signup_page():
st.title("Sign Up")
email = st.text_input("Email")
username = st.text_input("Username")
password = st.text_input("Password", type="password")
confirm_password = st.text_input("Confirm Password", type="password")
if len(username) < 3:
st.error("Username must be at least 3 characters long.")
return
if len(password) < 6:
st.error("Password must be at least 6 characters long.")
return
if password != confirm_password:
st.error("Passwords do not match.")
return
with col2:
if st.button("Back to Login"):
st.session_state.show_signup = False
st.rerun()
# Main Application
if __name__ == "__main__":
initialize_session_state()
if st.session_state.authenticated:
chat_interface()
else:
auth_pages()
35
9. Project Output Screens
Login page
36
Signup page
37
New chat session
38
Forget Password Page
39
OTP Page
40
Reset Password Page
41
Thinking Stage
42
Response to the Prompt
43
New Session Chat
44
Renaming of Session
45
10. Minimum and Recommended Hardware
Specifications
Development Environment
● IDE/Text Editors:
o Visual Studio Code (for front-end and back-end coding)
● Programming Languages
o Python
● Database
o AstraDB Endpoint and Token
46
● Large Language Model
o Hugging Face API
o Deepseek LLM Endpoint
● Application Programming Interface(API)
o Rapid API
47
11. Conclusion
The project aimed to develop a robust and efficient system that addresses specific user needs by
integrating cutting-edge technologies and streamlined functionalities. The primary objective was to
enhance usability, improve performance, and ensure a seamless experience for end-users.
Throughout the development process, various phases were meticulously executed, including
requirement gathering, system analysis, design, implementation, and testing. The project followed a
structured approach to ensure that all aspects were aligned with the defined objectives. By leveraging
advanced technologies, efficient algorithms, and user-centric design principles, the system
successfully delivered on its intended purpose.
The project demonstrated several key strengths, including high efficiency, scalability,
user-friendliness, and reliability. It not only met but exceeded initial expectations by providing
enhanced security, improved data management, and optimized resource utilization. The integration of
modern frameworks and tools further ensured that the system remains adaptable for future
enhancements.
48
and real-time threat monitoring, will enhance data protection and system integrity.
● Cross-Platform Compatibility
Expanding the system’s compatibility across multiple platforms, including mobile
applications and web-based versions, will broaden its accessibility and user base.
● Improved Data Analytics and Reporting
Implementing more advanced data analytics tools, visualization techniques, and predictive
modeling will provide deeper insights and drive more informed decision-making.
● User Experience Refinements
Continuous improvements in UI/UX design, incorporating feedback and usability testing, will
ensure that the system remains intuitive, engaging, and user-friendly.
● Support for Multi-Language and Localization
Expanding language support and localization options will make the system more accessible to
a diverse user base worldwide.
● Integration with Emerging Technologies
Future updates could explore integrations with blockchain, IoT, or augmented reality (AR) to
expand the system’s capabilities and industry applications.
49
12. Bibliography
12.2 Chatbot
● Chatgpt 4.o & 4.o mini
● Claude
● Deepseek
12.3 Documents
● Astra DB Docs
● Hugging Face Docs
50
51