naveen07garg commited on
Commit
24a4b4f
Β·
verified Β·
1 Parent(s): cf847e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import json
2
  import re
3
- import os, requests
4
  import fitz # PyMuPDF We use PyMuPDF (fitz) to capture hierarchy (section β†’ subsection β†’ subsubsection β†’ content/bullets).
5
  from collections import Counter
6
  from fastapi import FastAPI
@@ -591,11 +591,24 @@ def startup_event():
591
  # return generate_rag_response(req.query, retriever, k=req.top_k)
592
 
593
 
 
 
 
 
 
 
 
 
 
 
 
 
594
  # =============================
595
  # Step 5: Chat Function
596
  # =============================
597
  def chat_fn(message, history):
598
  global retriever
 
599
  if retriever is None:
600
  return "⚠️ Retriever not initialized. Please rebuild or check vector DB."
601
  answer = generate_rag_response(message, retriever)
 
1
  import json
2
  import re
3
+ import os, requests, time
4
  import fitz # PyMuPDF We use PyMuPDF (fitz) to capture hierarchy (section β†’ subsection β†’ subsubsection β†’ content/bullets).
5
  from collections import Counter
6
  from fastapi import FastAPI
 
591
  # return generate_rag_response(req.query, retriever, k=req.top_k)
592
 
593
 
594
+
595
+
596
+ def wait_for_key(key_name="OPENAI_API_KEY", timeout=10):
597
+ for _ in range(timeout):
598
+ if os.getenv(key_name):
599
+ print(f"βœ… {key_name} available.")
600
+ return True
601
+ print(f"⏳ Waiting for {key_name}...")
602
+ time.sleep(1)
603
+ print(f"❌ {key_name} not found after {timeout} seconds.")
604
+ return False
605
+
606
  # =============================
607
  # Step 5: Chat Function
608
  # =============================
609
  def chat_fn(message, history):
610
  global retriever
611
+ wait_for_key()
612
  if retriever is None:
613
  return "⚠️ Retriever not initialized. Please rebuild or check vector DB."
614
  answer = generate_rag_response(message, retriever)