Tesneem commited on
Commit
1cd5e38
·
verified ·
1 Parent(s): 60b3f78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -446,7 +446,35 @@ def rerank_with_topics(chunks, topics, alpha=0.2):
446
 
447
 
448
  # =================== Streamlit UI ===================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  def main():
 
 
450
  # st.set_page_config(page_title="Grant Buddy RAG", page_icon="🤖")
451
  st.title("🤖 Grant Buddy: Grant-Writing Assistant")
452
  USE_OPENAI = st.sidebar.checkbox("Use OpenAI (Costs Tokens)", value=False)
@@ -467,6 +495,7 @@ def main():
467
 
468
  # # retriever = init_vector_search().as_retriever(search_kwargs={"k": k_value, "score_threshold": score_threshold})
469
  retriever = init_vector_search().as_retriever()
 
470
 
471
  # pre_k = k_value*4 # Retrieve more chunks first
472
  # context_docs = retriever.get_relevant_documents(query, k=pre_k)
 
446
 
447
 
448
  # =================== Streamlit UI ===================
449
+ def gate_ui():
450
+ # Get password from secrets (optional env fallback)
451
+ APP_PASSWORD = st.secrets.get("APP_PASSWORD", os.getenv("APP_PASSWORD", "")).strip()
452
+
453
+ # Persist auth in session
454
+ if "authed" not in st.session_state:
455
+ st.session_state.authed = False
456
+
457
+ if st.session_state.authed:
458
+ return True
459
+
460
+ st.title("🔒 Grant Buddy Login")
461
+ pwd = st.text_input("Enter password", type="password")
462
+ col1, col2 = st.columns([1,1])
463
+ with col1:
464
+ if st.button("Login"):
465
+ if APP_PASSWORD and pwd == APP_PASSWORD:
466
+ st.session_state.authed = True
467
+ st.experimental_rerun()
468
+ else:
469
+ st.error("Incorrect password.")
470
+ with col2:
471
+ if st.button("Forgot?"):
472
+ st.info("Contact the admin to reset the APP_PASSWORD secret.")
473
+ return False
474
+
475
  def main():
476
+ if not gate_uit:
477
+ return
478
  # st.set_page_config(page_title="Grant Buddy RAG", page_icon="🤖")
479
  st.title("🤖 Grant Buddy: Grant-Writing Assistant")
480
  USE_OPENAI = st.sidebar.checkbox("Use OpenAI (Costs Tokens)", value=False)
 
495
 
496
  # # retriever = init_vector_search().as_retriever(search_kwargs={"k": k_value, "score_threshold": score_threshold})
497
  retriever = init_vector_search().as_retriever()
498
+ vectorstore = init_vector_search()
499
 
500
  # pre_k = k_value*4 # Retrieve more chunks first
501
  # context_docs = retriever.get_relevant_documents(query, k=pre_k)