Spaces:
Sleeping
Sleeping
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. | |
""") |