singhankur01 commited on
Commit
57b098a
·
verified ·
1 Parent(s): e616961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -43,12 +43,12 @@ async def lifespan(app: FastAPI):
43
  if not GOOGLE_API_KEY:
44
  raise RuntimeError("CRITICAL: Missing GOOGLE_API_KEY in environment secrets!")
45
 
46
- # Load models into the shared dictionary
47
- ml_models["embedder"] = HuggingFaceEmbeddings(model_name="BAAI/bge-base-en-v1.5")
48
- cross_encoder_model = HuggingFaceCrossEncoder(model_name="BAAI/bge-reranker-large")
49
- ml_models["reranker_compressor"] = CrossEncoderReranker(model=cross_encoder_model, top_n=5)
50
- ml_models["llm"] = ChatGoogleGenerativeAI(model="gemini-1.5-flash", api_key=GOOGLE_API_KEY)
51
- ml_models["prompt_template"] = PromptTemplate.from_template(
52
  """
53
  You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.
54
 
@@ -85,12 +85,13 @@ Else:
85
  ##NOTE : Do not mention document id or its page number just mention clauses if applicable .
86
  """
87
  )
88
- print("✅ Models and prompt loaded successfully!")
89
-
 
 
 
90
  yield
91
-
92
- # Code below yield runs on shutdown (optional)
93
- print("Shutting down and cleaning up.")
94
  ml_models.clear()
95
 
96
  # --- 2. FastAPI App Instance ---
 
43
  if not GOOGLE_API_KEY:
44
  raise RuntimeError("CRITICAL: Missing GOOGLE_API_KEY in environment secrets!")
45
 
46
+ # Load models into the shared dictionary
47
+ ml_models["embedder"] = HuggingFaceEmbeddings(model_name="BAAI/bge-base-en-v1.5")
48
+ cross_encoder_model = HuggingFaceCrossEncoder(model_name="BAAI/bge-reranker-large")
49
+ ml_models["reranker_compressor"] = CrossEncoderReranker(model=cross_encoder_model, top_n=5)
50
+ ml_models["llm"] = ChatGoogleGenerativeAI(model="gemini-1.5-flash", api_key=GOOGLE_API_KEY)
51
+ ml_models["prompt_template"] = PromptTemplate.from_template(
52
  """
53
  You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.
54
 
 
85
  ##NOTE : Do not mention document id or its page number just mention clauses if applicable .
86
  """
87
  )
88
+ print("✅ Models and prompt loaded successfully!")
89
+ except Exception as e:
90
+ print("❌ Lifespan error:", str(e))
91
+ raise e
92
+
93
  yield
94
+ print("🧹 Cleaning up.")
 
 
95
  ml_models.clear()
96
 
97
  # --- 2. FastAPI App Instance ---