Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -623,6 +623,36 @@ def initialize_model(self):
|
|
623 |
# st.error(f"Failed to initialize the system: {str(e)}")
|
624 |
# raise
|
625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
# def main():
|
627 |
# try:
|
628 |
# # Environment check
|
@@ -911,6 +941,10 @@ def initialize_model(self):
|
|
911 |
|
912 |
def main():
|
913 |
try:
|
|
|
|
|
|
|
|
|
914 |
# Environment check
|
915 |
if not check_environment():
|
916 |
return
|
|
|
623 |
# st.error(f"Failed to initialize the system: {str(e)}")
|
624 |
# raise
|
625 |
|
626 |
+
@st.cache_resource(show_spinner=False)
|
627 |
+
def initialize_rag_pipeline():
|
628 |
+
"""Initialize the RAG pipeline once"""
|
629 |
+
try:
|
630 |
+
data_folder = "ESPN_data"
|
631 |
+
if not os.path.exists(data_folder):
|
632 |
+
os.makedirs(data_folder, exist_ok=True)
|
633 |
+
|
634 |
+
# Load embeddings first
|
635 |
+
drive_file_id = "1MuV63AE9o6zR9aBvdSDQOUextp71r2NN"
|
636 |
+
with st.spinner("Loading data..."):
|
637 |
+
cache_data = load_from_drive(drive_file_id)
|
638 |
+
if cache_data is None:
|
639 |
+
st.error("Failed to load embeddings from Google Drive")
|
640 |
+
st.stop()
|
641 |
+
|
642 |
+
# Initialize pipeline
|
643 |
+
rag = RAGPipeline(data_folder)
|
644 |
+
|
645 |
+
# Store embeddings
|
646 |
+
rag.documents = cache_data['documents']
|
647 |
+
rag.retriever.store_embeddings(cache_data['embeddings'])
|
648 |
+
|
649 |
+
return rag
|
650 |
+
|
651 |
+
except Exception as e:
|
652 |
+
logging.error(f"Pipeline initialization error: {str(e)}")
|
653 |
+
st.error(f"Failed to initialize the system: {str(e)}")
|
654 |
+
raise
|
655 |
+
|
656 |
# def main():
|
657 |
# try:
|
658 |
# # Environment check
|
|
|
941 |
|
942 |
def main():
|
943 |
try:
|
944 |
+
# First, check if model exists
|
945 |
+
model_path = os.path.join("models", "mistral-7b-v0.1.Q4_K_M.gguf")
|
946 |
+
if not os.path.exists(model_path):
|
947 |
+
st.warning("⚠️ First-time setup: The model will be downloaded. This takes a few minutes but only happens once.")
|
948 |
# Environment check
|
949 |
if not check_environment():
|
950 |
return
|