File size: 1,962 Bytes
0628cbb
 
40b71eb
0628cbb
 
40b71eb
 
 
 
17a737c
 
 
0628cbb
17a737c
 
 
 
0628cbb
17a737c
 
 
 
 
 
 
 
 
 
0628cbb
 
17a737c
 
 
 
 
 
 
 
0628cbb
 
 
17a737c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import streamlit as st

# FIRST: Set page config before ANY other Streamlit command
st.set_page_config(page_title="Indian Spiritual RAG")

# THEN: Import your modules
from rag_engine import process_query, load_model
from utils import setup_all_auth

# Display title
st.title("Indian Spiritual Texts Q&A")

# Setup all authentication
try:
    setup_all_auth()
except Exception as e:
    st.error(f"Authentication error: {str(e)}")

# Preload the model to avoid session state issues
try:
    with st.spinner("Initializing... This may take a minute."):
        # Force model loading at startup to avoid session state issues
        load_model()
        st.success("System initialized successfully!")
except Exception as e:
    st.error(f"Error initializing: {str(e)}")

# Query input
query = st.text_input("Ask your question:")

# Sliders for customization
col1, col2 = st.columns(2)
with col1:
    top_k = st.slider("Number of sources:", 3, 10, 5)
with col2:
    word_limit = st.slider("Word limit:", 50, 500, 200)

# Process button
if st.button("Get Answer"):
    if query:
        with st.spinner("Processing..."):
            try:
                result = process_query(query, top_k=top_k, word_limit=word_limit)
                
                st.subheader("Answer:")
                st.write(result["answer_with_rag"])
                
                st.subheader("Sources:")
                for citation in result["citations"].split("\n"):
                    st.write(citation)
            except Exception as e:
                st.error(f"Error processing query: {str(e)}")
    else:
        st.warning("Please enter a question first.")

# Add helpful information
st.markdown("---")
st.markdown("""
### About this app
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about Indian spiritual texts. 
It searches through a database of texts to find relevant passages and generates answers based on those passages.
""")