Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
-
from
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from langchain.vectorstores import Chroma
|
| 5 |
from langchain.chains import RetrievalQA
|
| 6 |
from langchain.prompts import PromptTemplate
|
| 7 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -46,13 +45,10 @@ def setup_qa_chain(vector_db, llm):
|
|
| 46 |
|
| 47 |
prompt_template = """You are a knowledgeable spiritual guide specialized in the Bhagavad Gita, an ancient Hindu scripture.
|
| 48 |
Your task is to answer questions based on the relevant verses from the Bhagavad Gita in Sanskrit and Hindi only. If the user ask for translation than only answer in English.
|
| 49 |
-
|
| 50 |
CONTEXT INFORMATION:
|
| 51 |
{context}
|
| 52 |
-
|
| 53 |
USER QUESTION:
|
| 54 |
{question}
|
| 55 |
-
|
| 56 |
Please provide a comprehensive answer to the user's question by following these guidelines:
|
| 57 |
1. Format your response with clear headings (use ## for main sections, ### for subsections) and paragraphs for readability.
|
| 58 |
2. Always cite the specific chapter and verse numbers (e.g., Chapter 2, Verse 47) when referencing the scripture.
|
|
@@ -68,7 +64,6 @@ Please provide a comprehensive answer to the user's question by following these
|
|
| 68 |
8. If the context doesn't fully answer the question, acknowledge this and provide the best answer based on the available verses.
|
| 69 |
9. If asked for a verse in Sanskrit, provide both the Sanskrit text (in Devanagari if requested) and the transliteration.
|
| 70 |
10. You can answer in English, Hindi, or Sanskrit based on the user's preferred language.
|
| 71 |
-
|
| 72 |
ANSWER:
|
| 73 |
"""
|
| 74 |
|
|
@@ -124,7 +119,6 @@ example_questions = [
|
|
| 124 |
with gr.Blocks(theme="soft") as app:
|
| 125 |
gr.Markdown("""
|
| 126 |
# 🕉️ Bhagavad Gita Wisdom Guide
|
| 127 |
-
|
| 128 |
Ask questions about the Bhagavad Gita and receive insights from this ancient sacred text.
|
| 129 |
The guide can answer questions about specific verses, concepts, teachings, and applications of the Gita.
|
| 130 |
""")
|
|
@@ -138,33 +132,6 @@ with gr.Blocks(theme="soft") as app:
|
|
| 138 |
analytics_enabled=False
|
| 139 |
)
|
| 140 |
|
| 141 |
-
# with gr.Column(scale=1):
|
| 142 |
-
# gr.Markdown("""
|
| 143 |
-
# ### About this Guide
|
| 144 |
-
|
| 145 |
-
# This application uses AI to help you explore the wisdom of the Bhagavad Gita.
|
| 146 |
-
|
| 147 |
-
# You can ask about:
|
| 148 |
-
# - Specific verses
|
| 149 |
-
# - Philosophical concepts
|
| 150 |
-
# - Practical applications
|
| 151 |
-
# - Sanskrit terminology
|
| 152 |
-
|
| 153 |
-
# The guide draws from the Bhagavad Gita text to provide accurate information.
|
| 154 |
-
# """)
|
| 155 |
-
|
| 156 |
-
# gr.Markdown("""
|
| 157 |
-
# ### Sample Topics
|
| 158 |
-
|
| 159 |
-
# - Dharma (duty)
|
| 160 |
-
# - Karma (action)
|
| 161 |
-
# - Atman (soul)
|
| 162 |
-
# - Meditation techniques
|
| 163 |
-
# - Handling emotions
|
| 164 |
-
# - Spiritual practices
|
| 165 |
-
# - Moksha (liberation)
|
| 166 |
-
# """)
|
| 167 |
-
|
| 168 |
gr.Markdown("""
|
| 169 |
*This guide provides information based on the Bhagavad Gita text. For spiritual guidance, please consult with qualified teachers.*
|
| 170 |
""")
|
|
|
|
| 1 |
+
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
| 2 |
+
from langchain_community.document_loaders import PyPDFLoader, DirectoryLoader
|
| 3 |
+
from langchain_community.vectorstores import Chroma
|
|
|
|
| 4 |
from langchain.chains import RetrievalQA
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 45 |
|
| 46 |
prompt_template = """You are a knowledgeable spiritual guide specialized in the Bhagavad Gita, an ancient Hindu scripture.
|
| 47 |
Your task is to answer questions based on the relevant verses from the Bhagavad Gita in Sanskrit and Hindi only. If the user ask for translation than only answer in English.
|
|
|
|
| 48 |
CONTEXT INFORMATION:
|
| 49 |
{context}
|
|
|
|
| 50 |
USER QUESTION:
|
| 51 |
{question}
|
|
|
|
| 52 |
Please provide a comprehensive answer to the user's question by following these guidelines:
|
| 53 |
1. Format your response with clear headings (use ## for main sections, ### for subsections) and paragraphs for readability.
|
| 54 |
2. Always cite the specific chapter and verse numbers (e.g., Chapter 2, Verse 47) when referencing the scripture.
|
|
|
|
| 64 |
8. If the context doesn't fully answer the question, acknowledge this and provide the best answer based on the available verses.
|
| 65 |
9. If asked for a verse in Sanskrit, provide both the Sanskrit text (in Devanagari if requested) and the transliteration.
|
| 66 |
10. You can answer in English, Hindi, or Sanskrit based on the user's preferred language.
|
|
|
|
| 67 |
ANSWER:
|
| 68 |
"""
|
| 69 |
|
|
|
|
| 119 |
with gr.Blocks(theme="soft") as app:
|
| 120 |
gr.Markdown("""
|
| 121 |
# 🕉️ Bhagavad Gita Wisdom Guide
|
|
|
|
| 122 |
Ask questions about the Bhagavad Gita and receive insights from this ancient sacred text.
|
| 123 |
The guide can answer questions about specific verses, concepts, teachings, and applications of the Gita.
|
| 124 |
""")
|
|
|
|
| 132 |
analytics_enabled=False
|
| 133 |
)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
gr.Markdown("""
|
| 136 |
*This guide provides information based on the Bhagavad Gita text. For spiritual guidance, please consult with qualified teachers.*
|
| 137 |
""")
|