Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,60 @@
|
|
1 |
import streamlit as st
|
2 |
-
from rag_engine import process_query
|
3 |
from utils import setup_all_auth
|
4 |
|
|
|
5 |
st.set_page_config(page_title="Indian Spiritual RAG")
|
6 |
|
|
|
|
|
|
|
7 |
# Setup all authentication
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
query = st.text_input("Ask your question:")
|
12 |
-
top_k = st.slider("Number of sources:", 3, 10, 5)
|
13 |
-
word_limit = st.slider("Word limit:", 50, 500, 200)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if st.button("Get Answer"):
|
16 |
if query:
|
17 |
with st.spinner("Processing..."):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from rag_engine import process_query, load_model
|
3 |
from utils import setup_all_auth
|
4 |
|
5 |
+
# Page configuration
|
6 |
st.set_page_config(page_title="Indian Spiritual RAG")
|
7 |
|
8 |
+
# Display title
|
9 |
+
st.title("Indian Spiritual Texts Q&A")
|
10 |
+
|
11 |
# Setup all authentication
|
12 |
+
try:
|
13 |
+
setup_all_auth()
|
14 |
+
except Exception as e:
|
15 |
+
st.error(f"Authentication error: {str(e)}")
|
16 |
|
17 |
+
# Preload the model to avoid session state issues
|
18 |
+
try:
|
19 |
+
with st.spinner("Initializing... This may take a minute."):
|
20 |
+
# Force model loading at startup to avoid session state issues
|
21 |
+
load_model()
|
22 |
+
st.success("System initialized successfully!")
|
23 |
+
except Exception as e:
|
24 |
+
st.error(f"Error initializing: {str(e)}")
|
25 |
+
|
26 |
+
# Query input
|
27 |
query = st.text_input("Ask your question:")
|
|
|
|
|
28 |
|
29 |
+
# Sliders for customization
|
30 |
+
col1, col2 = st.columns(2)
|
31 |
+
with col1:
|
32 |
+
top_k = st.slider("Number of sources:", 3, 10, 5)
|
33 |
+
with col2:
|
34 |
+
word_limit = st.slider("Word limit:", 50, 500, 200)
|
35 |
+
|
36 |
+
# Process button
|
37 |
if st.button("Get Answer"):
|
38 |
if query:
|
39 |
with st.spinner("Processing..."):
|
40 |
+
try:
|
41 |
+
result = process_query(query, top_k=top_k, word_limit=word_limit)
|
42 |
+
|
43 |
+
st.subheader("Answer:")
|
44 |
+
st.write(result["answer_with_rag"])
|
45 |
+
|
46 |
+
st.subheader("Sources:")
|
47 |
+
for citation in result["citations"].split("\n"):
|
48 |
+
st.write(citation)
|
49 |
+
except Exception as e:
|
50 |
+
st.error(f"Error processing query: {str(e)}")
|
51 |
+
else:
|
52 |
+
st.warning("Please enter a question first.")
|
53 |
+
|
54 |
+
# Add helpful information
|
55 |
+
st.markdown("---")
|
56 |
+
st.markdown("""
|
57 |
+
### About this app
|
58 |
+
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about Indian spiritual texts.
|
59 |
+
It searches through a database of texts to find relevant passages and generates answers based on those passages.
|
60 |
+
""")
|