amaherovskyi commited on
Commit
fdcc774
·
verified ·
1 Parent(s): a4bfffb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -28,9 +28,7 @@ DEFAULT_RETRIEVE_K = 30
28
  DEFAULT_RERANK_K = 5
29
 
30
 
31
- # -------------------------
32
  # Lazy Initialization
33
- # -------------------------
34
  def init_once() -> Tuple[
35
  List[Dict[str, Any]], Any, Any, Any, Any
36
  ]:
@@ -62,9 +60,7 @@ def init_once() -> Tuple[
62
  return _documents, _model, _faiss_index, _bm25_index, _reranker_model
63
 
64
 
65
- # -------------------------
66
  # Main RAG Handler
67
- # -------------------------
68
  def answer_question(
69
  llm_key: str,
70
  query: str,
@@ -72,10 +68,10 @@ def answer_question(
72
  ) -> Tuple[str, str]:
73
 
74
  if not query.strip():
75
- return "⚠️ Please enter a question.", ""
76
 
77
  if not llm_key.strip():
78
- return "⚠️ Please provide a valid GROQ API key.", ""
79
 
80
  # load cached resources
81
  documents, model, faiss_idx, bm25_idx, reranker = init_once()
@@ -84,7 +80,7 @@ def answer_question(
84
  try:
85
  llm_client = init_groq(api_key=llm_key)
86
  except Exception:
87
- return "Invalid GROQ API key.", ""
88
 
89
  # run RAG pipeline
90
  result = rag_pipeline(
@@ -116,9 +112,7 @@ def answer_question(
116
  return result["answer"], docs_preview
117
 
118
 
119
- # -------------------------
120
  # Gradio UI
121
- # -------------------------
122
  with gr.Blocks(title="Financial RAG QA System") as demo:
123
 
124
  gr.Markdown("""
 
28
  DEFAULT_RERANK_K = 5
29
 
30
 
 
31
  # Lazy Initialization
 
32
  def init_once() -> Tuple[
33
  List[Dict[str, Any]], Any, Any, Any, Any
34
  ]:
 
60
  return _documents, _model, _faiss_index, _bm25_index, _reranker_model
61
 
62
 
 
63
  # Main RAG Handler
 
64
  def answer_question(
65
  llm_key: str,
66
  query: str,
 
68
  ) -> Tuple[str, str]:
69
 
70
  if not query.strip():
71
+ return "Please enter a question.", ""
72
 
73
  if not llm_key.strip():
74
+ return "Please provide a valid GROQ API key.", ""
75
 
76
  # load cached resources
77
  documents, model, faiss_idx, bm25_idx, reranker = init_once()
 
80
  try:
81
  llm_client = init_groq(api_key=llm_key)
82
  except Exception:
83
+ return "Invalid GROQ API key.", ""
84
 
85
  # run RAG pipeline
86
  result = rag_pipeline(
 
112
  return result["answer"], docs_preview
113
 
114
 
 
115
  # Gradio UI
 
116
  with gr.Blocks(title="Financial RAG QA System") as demo:
117
 
118
  gr.Markdown("""