The aim of this blog is to make you walkthrough an AI chatbot named BhagavadGitaGPT that offers spiritual guidance using the teachings of the Bhagavad Gita. This chatbot uses natural language processing to understand and answer users' questions, providing insights and advice based on the ancient Hindu scripture.
The requirements for the chatbot are as follows.
- Streamlit
- google-generative AI
The htmlTemplates.py file can be modified as per required font and background.
#htmlTemplates.py
css = '''
<style>
.chat-message {
padding: 1.5rem; border-radius: 0.5rem; margin-bottom: 1rem; display: flex
}
.chat-message.user {
background-color: #2b313e
}
.chat-message.bot {
background-color: #475063
}
.chat-message .avatar {
width: 20%;
}
.chat-message .avatar img {
max-width: 78px;
max-height: 78px;
border-radius: 50%;
object-fit: cover;
}
.chat-message .message {
width: 80%;
padding: 0 1.5rem;
color: #fff;
}
'''
bot_template = '''
<div class="chat-message bot">
<div class="avatar">
<img src="https://i.ibb.co/cN0nmSj/Screenshot-2023-05-28-at-02-37-21.png" style="max-height: 78px; max-width: 78px; border-radius: 50%; object-fit: cover;">
</div>
<div class="message">{{MSG}}</div>
</div>
'''
user_template = '''
<div class="chat-message user">
<div class="avatar">
<img src="https://i.ibb.co/rdZC7LZ/Photo-logo-1.png">
</div>
<div class="message">{{MSG}}</div>
</div>
'''Next, we need to implement code for app file where we provide an API key and PALM 2 model named "models/text-bison-001" in order to chat with the bot based on teachings of Bhagavad Gita.
#app.py
import google.generativeai as palm
import streamlit as st
import os
# Set your API key
palm.configure(api_key = os.environ['PALM_KEY'])
# Select the PaLM 2 model
model = 'models/text-bison-001'
# Generate text
if prompt := st.chat_input("Ask your query..."):
enprom = f"""Answer the below provided input in context to Bhagwad Geeta. Use the verses and chapters sentences as references to your answer with suggestions
coming from Bhagwad Geeta. Your answer to below input should only be in context to Bhagwad geeta only.\nInput= {prompt}"""
completion = palm.generate_text(model=model, prompt=enprom, temperature=0.5, max_output_tokens=800)
# response = palm.chat(messages=["Hello."])
# print(response.last) # 'Hello! What can I help you with?'
# response.reply("Can you tell me a joke?")
# Print the generated text
with st.chat_message("Assistant"):
st.write(completion.result)After writing these codes, you need to create a streamlit space at Huggingface (Hugging Face — The AI community building the future.) and upload all files. After uploading all the codes and the pdf of the Bhagavad Gita, you can start talking with Krishna to solve your life problems.

You can access the complete code and bhagavad gita pdf from jyotidabass/BhagavadGita-chatbot-to-talk-with-krishna (github.com).
Cheers!! Happy reading!! Keep learning!!
Please upvote if you liked this!! Thanks!!
PlainEnglish.io 🚀
Thank you for being a part of the In Plain English community! Before you go:
- Be sure to clap and follow the writer️
- Learn how you can also write for In Plain English️
- Follow us: X | LinkedIn | YouTube | Discord | Newsletter
- Visit our other platforms: Stackademic | CoFeed | Venture