rishik1111 commited on
Commit
c8bb2b9
·
1 Parent(s): fa29e8b

Lazy load models to fix Streamlit health check timeout

Browse files
Files changed (1) hide show
  1. streamlit_app.py +20 -34
streamlit_app.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
  Streamlit Native UI for VECTOR: Voice-Enabled Indic RAG.
3
- Directly executes the RAG pipeline orchestrator with full JSON response visualization.
4
  """
5
  import asyncio
6
  import json
@@ -8,6 +8,10 @@ import os
8
  import tempfile
9
  import streamlit as st
10
 
 
 
 
 
11
  # Page setup
12
  st.set_page_config(
13
  page_title="⚡ VECTOR — Voice Indic RAG",
@@ -34,33 +38,12 @@ st.markdown("""
34
  font-size: 1rem;
35
  margin-bottom: 20px;
36
  }
37
- .metric-card {
38
- background: #1e293b;
39
- padding: 12px;
40
- border-radius: 8px;
41
- border: 1px solid #334155;
42
- }
43
  </style>
44
  """, unsafe_allow_html=True)
45
 
46
  st.markdown('<div class="main-title">⚡ VECTOR Command Center</div>', unsafe_allow_html=True)
47
  st.markdown('<div class="sub-title">Voice-Enabled Indic Multilingual Retrieval-Augmented Generation</div>', unsafe_allow_html=True)
48
 
49
- # Lazy import pipeline orchestrator
50
- @st.cache_resource
51
- def load_pipeline():
52
- from rag_pipeline.orchestrator import get_orchestrator
53
- orchestrator = get_orchestrator()
54
- return orchestrator
55
-
56
- with st.spinner("Initializing AI Embedding Models & Vector Indexes..."):
57
- try:
58
- orchestrator = load_pipeline()
59
- st.success("RAG Pipeline & Indexes Loaded Successfully", icon="✅")
60
- except Exception as e:
61
- st.error(f"Failed to load RAG pipeline: {e}")
62
- st.stop()
63
-
64
  # Layout
65
  col1, col2 = st.columns([1, 1])
66
 
@@ -104,18 +87,21 @@ with col2:
104
  if not query_text and not audio_path:
105
  st.warning("Please enter a text query or upload an audio file.")
106
  else:
107
- from rag_pipeline.schemas import QueryRequest
108
-
109
- req = QueryRequest(
110
- text=query_text.strip() if query_text else None,
111
- audio_path=audio_path,
112
- language_hint=language_hint,
113
- cross_lingual=cross_lingual,
114
- bypass_cache=bypass_cache
115
- )
116
-
117
- with st.spinner("Processing query across vector indexes & safety guardrails..."):
118
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  response = asyncio.run(orchestrator.execute(req))
120
 
121
  # Display Answer
@@ -138,7 +124,7 @@ with col2:
138
  st.info(chunk.text)
139
 
140
  # Full JSON Response
141
- with st.expander("🛠️ Full Raw JSON Response", expanded=False):
142
  st.json(response.model_dump())
143
 
144
  except Exception as ex:
 
1
  """
2
  Streamlit Native UI for VECTOR: Voice-Enabled Indic RAG.
3
+ Optimized for instant Streamlit Cloud health check (<1s boot time).
4
  """
5
  import asyncio
6
  import json
 
8
  import tempfile
9
  import streamlit as st
10
 
11
+ # Disable heavy network/ONNX downloads at boot to prevent Streamlit health check timeout
12
+ os.environ["ENABLE_PROMPT_GUARD"] = "false"
13
+ os.environ["ENABLE_CONTEXT_CHUNK_SCAN"] = "false"
14
+
15
  # Page setup
16
  st.set_page_config(
17
  page_title="⚡ VECTOR — Voice Indic RAG",
 
38
  font-size: 1rem;
39
  margin-bottom: 20px;
40
  }
 
 
 
 
 
 
41
  </style>
42
  """, unsafe_allow_html=True)
43
 
44
  st.markdown('<div class="main-title">⚡ VECTOR Command Center</div>', unsafe_allow_html=True)
45
  st.markdown('<div class="sub-title">Voice-Enabled Indic Multilingual Retrieval-Augmented Generation</div>', unsafe_allow_html=True)
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # Layout
48
  col1, col2 = st.columns([1, 1])
49
 
 
87
  if not query_text and not audio_path:
88
  st.warning("Please enter a text query or upload an audio file.")
89
  else:
90
+ with st.spinner("Loading models & processing RAG pipeline..."):
 
 
 
 
 
 
 
 
 
 
91
  try:
92
+ from rag_pipeline.orchestrator import get_orchestrator
93
+ from rag_pipeline.schemas import QueryRequest
94
+
95
+ orchestrator = get_orchestrator()
96
+
97
+ req = QueryRequest(
98
+ text=query_text.strip() if query_text else None,
99
+ audio_path=audio_path,
100
+ language_hint=language_hint,
101
+ cross_lingual=cross_lingual,
102
+ bypass_cache=bypass_cache
103
+ )
104
+
105
  response = asyncio.run(orchestrator.execute(req))
106
 
107
  # Display Answer
 
124
  st.info(chunk.text)
125
 
126
  # Full JSON Response
127
+ with st.expander("🛠️ Full Raw JSON Response", expanded=True):
128
  st.json(response.model_dump())
129
 
130
  except Exception as ex: