Spaces:
Build error
Build error
Update app.py
#2
by
arpita-23
- opened
app.py
CHANGED
|
@@ -59,7 +59,7 @@ def fetch_daily_quote():
|
|
| 59 |
# Streamlit UI
|
| 60 |
st.set_page_config(
|
| 61 |
page_title="Bhagavad Gita & Yoga Sutras Assistant",
|
| 62 |
-
page_icon="
|
| 63 |
layout="wide"
|
| 64 |
)
|
| 65 |
|
|
@@ -95,7 +95,7 @@ quote = fetch_daily_quote()
|
|
| 95 |
st.markdown(
|
| 96 |
f"""
|
| 97 |
<div style="text-align: center; background-color: #f0f8ff; padding: 10px; border-radius: 5px; margin-bottom: 20px;">
|
| 98 |
-
<h4
|
| 99 |
</div>
|
| 100 |
""",
|
| 101 |
unsafe_allow_html=True
|
|
@@ -114,7 +114,7 @@ if st.session_state.chat_started:
|
|
| 114 |
], index=0)
|
| 115 |
|
| 116 |
# Display chat history
|
| 117 |
-
st.markdown("###
|
| 118 |
if "chat_history" in st.session_state:
|
| 119 |
for chat in st.session_state.chat_history:
|
| 120 |
st.markdown(f"**{st.session_state.user_name}:** {chat['question']}")
|
|
@@ -136,28 +136,37 @@ if st.session_state.chat_started:
|
|
| 136 |
source_documents = response.get("source_documents", [])
|
| 137 |
execution_time = round(end_time - start_time, 2)
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
# Translate response if needed
|
| 140 |
if selected_language != "English":
|
| 141 |
translator = GoogleTranslator(source="en", target=selected_language.lower())
|
| 142 |
-
|
| 143 |
-
else:
|
| 144 |
-
translated_answer = answer
|
| 145 |
|
| 146 |
# Save chat history
|
| 147 |
if "chat_history" not in st.session_state:
|
| 148 |
st.session_state.chat_history = []
|
| 149 |
st.session_state.chat_history.append({
|
| 150 |
"question": user_query.strip(),
|
| 151 |
-
"answer":
|
| 152 |
})
|
| 153 |
|
| 154 |
# Display source documents if available
|
| 155 |
if source_documents:
|
| 156 |
-
with st.expander("
|
| 157 |
for i, doc in enumerate(source_documents):
|
| 158 |
st.write(f"**Document {i + 1}:** {doc.page_content}")
|
| 159 |
|
| 160 |
-
st.write(f"
|
| 161 |
st.write(f"_Response time: {execution_time} seconds_")
|
| 162 |
|
| 163 |
# Sharing options
|
|
|
|
| 59 |
# Streamlit UI
|
| 60 |
st.set_page_config(
|
| 61 |
page_title="Bhagavad Gita & Yoga Sutras Assistant",
|
| 62 |
+
page_icon="\uD83D\uDD0D",
|
| 63 |
layout="wide"
|
| 64 |
)
|
| 65 |
|
|
|
|
| 95 |
st.markdown(
|
| 96 |
f"""
|
| 97 |
<div style="text-align: center; background-color: #f0f8ff; padding: 10px; border-radius: 5px; margin-bottom: 20px;">
|
| 98 |
+
<h4>\u2728 Daily Wisdom: <a href="{quote}" target="_blank">{quote}</a></h4>
|
| 99 |
</div>
|
| 100 |
""",
|
| 101 |
unsafe_allow_html=True
|
|
|
|
| 114 |
], index=0)
|
| 115 |
|
| 116 |
# Display chat history
|
| 117 |
+
st.markdown("### \uD83D\uDCAC Chat History")
|
| 118 |
if "chat_history" in st.session_state:
|
| 119 |
for chat in st.session_state.chat_history:
|
| 120 |
st.markdown(f"**{st.session_state.user_name}:** {chat['question']}")
|
|
|
|
| 136 |
source_documents = response.get("source_documents", [])
|
| 137 |
execution_time = round(end_time - start_time, 2)
|
| 138 |
|
| 139 |
+
# Prepare JSON output
|
| 140 |
+
json_output = {
|
| 141 |
+
"book": "Gita" if "Gita" in answer else "PYS",
|
| 142 |
+
"chapter_number": response.get("metadata", {}).get("chapter_number", "Unknown"),
|
| 143 |
+
"verse_number": response.get("metadata", {}).get("verse_number", "Unknown"),
|
| 144 |
+
"shloka": response.get("shloka", "N/A"),
|
| 145 |
+
"translation": response.get("translation", answer),
|
| 146 |
+
"commentary": response.get("commentary", "N/A"),
|
| 147 |
+
"summary": response.get("summary", "N/A")
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
# Translate response if needed
|
| 151 |
if selected_language != "English":
|
| 152 |
translator = GoogleTranslator(source="en", target=selected_language.lower())
|
| 153 |
+
json_output["translation"] = translator.translate(json_output["translation"])
|
|
|
|
|
|
|
| 154 |
|
| 155 |
# Save chat history
|
| 156 |
if "chat_history" not in st.session_state:
|
| 157 |
st.session_state.chat_history = []
|
| 158 |
st.session_state.chat_history.append({
|
| 159 |
"question": user_query.strip(),
|
| 160 |
+
"answer": json_output["translation"]
|
| 161 |
})
|
| 162 |
|
| 163 |
# Display source documents if available
|
| 164 |
if source_documents:
|
| 165 |
+
with st.expander("\uD83D\uDCDC Source Documents"):
|
| 166 |
for i, doc in enumerate(source_documents):
|
| 167 |
st.write(f"**Document {i + 1}:** {doc.page_content}")
|
| 168 |
|
| 169 |
+
st.write(f"**\u2728 Enlightened Response (JSON Format):** {json.dumps(json_output, indent=4)}")
|
| 170 |
st.write(f"_Response time: {execution_time} seconds_")
|
| 171 |
|
| 172 |
# Sharing options
|