ankanghosh commited on
Commit
17a737c
·
verified ·
1 Parent(s): 38deecc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -13
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
- setup_all_auth()
 
 
 
9
 
10
- st.title("Indian Spiritual Texts Q&A")
 
 
 
 
 
 
 
 
 
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
- result = process_query(query, top_k=top_k, word_limit=word_limit)
19
-
20
- st.subheader("Answer:")
21
- st.write(result["answer_with_rag"])
22
-
23
- st.subheader("Sources:")
24
- for citation in result["citations"].split("\n"):
25
- st.write(citation)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """)