Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,7 +58,8 @@ PRELOAD_URLS = [
|
|
| 58 |
"https://hackrx.blob.core.windows.net/assets/indian_constitution.pdf?sv=2023-01-03&st=2025-07-28T06%3A42%3A00Z&se=2026-11-29T06%3A42%3A00Z&sr=b&sp=r&sig=5Gs%2FOXqP3zY00lgciu4BZjDV5QjTDIx7fgnfdz6Pu24%3D",
|
| 59 |
"https://hackrx.blob.core.windows.net/assets/UNI%20GROUP%20HEALTH%20INSURANCE%20POLICY%20-%20UIIHLGP26043V022526%201.pdf?sv=2023-01-03&spr=https&st=2025-07-31T17%3A06%3A03Z&se=2026-08-01T17%3A06%3A00Z&sr=b&sp=r&sig=wLlooaThgRx91i2z4WaeggT0qnuUUEzIUKj42GsvMfg%3D",
|
| 60 |
"https://hackrx.blob.core.windows.net/assets/Happy%20Family%20Floater%20-%202024%20OICHLIP25046V062425%201.pdf?sv=2023-01-03&spr=https&st=2025-07-31T17%3A24%3A30Z&se=2026-08-01T17%3A24%3A00Z&sr=b&sp=r&sig=VNMTTQUjdXGYb2F4Di4P0zNvmM2rTBoEHr%2BnkUXIqpQ%3D",
|
| 61 |
-
"https://dn790007.ca.archive.org/0/items/newtonspmathema00newtrich/newtonspmathema00newtrich.pdf"
|
|
|
|
| 62 |
]
|
| 63 |
|
| 64 |
|
|
@@ -104,22 +105,23 @@ async def lifespan(app: FastAPI):
|
|
| 104 |
max_output_tokens=300
|
| 105 |
)
|
| 106 |
ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
|
| 107 |
-
**Role**: You are an expert
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
**Context**:
|
| 110 |
{context}
|
| 111 |
|
| 112 |
**Query**: {full_query}
|
| 113 |
|
| 114 |
**Response**:
|
| 115 |
-
1. query: What is the waiting period for pre-existing diseases (PED) to be covered?
|
| 116 |
-
response: There is a waiting period of thirty-six (36) months of continuous coverage from the first policy inception for pre-existing diseases and their direct complications to be covered.
|
| 117 |
-
|
| 118 |
-
2. query: Are the medical expenses for an organ donor covered under this policy?
|
| 119 |
-
response : Yes, the policy indemnifies the medical expenses for the organ donor's hospitalization for the purpose of harvesting the organ, provided the organ is for an insured person and the donation complies with the Transplantation of Human Organs Act, 1994.
|
| 120 |
-
|
| 121 |
-
3. query: Does this policy cover maternity expenses, and what are the conditions?
|
| 122 |
-
response: Yes, the policy covers maternity expenses, including childbirth and lawful medical termination of pregnancy. To be eligible, the female insured person must have been continuously covered for at least 24 months. The benefit is limited to two deliveries or terminations during the policy period.
|
| 123 |
"""
|
| 124 |
)
|
| 125 |
|
|
@@ -232,7 +234,7 @@ async def run_hackrx(req: RunRequest):
|
|
| 232 |
keyword_retriever = BM25Retriever.from_documents(chunks)
|
| 233 |
keyword_retriever.k = 8
|
| 234 |
# dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
|
| 235 |
-
ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.
|
| 236 |
### to make it faster we are now using our built reranker thats why commenting the code below
|
| 237 |
# compression_retriever = ContextualCompressionRetriever(
|
| 238 |
# base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]
|
|
|
|
| 58 |
"https://hackrx.blob.core.windows.net/assets/indian_constitution.pdf?sv=2023-01-03&st=2025-07-28T06%3A42%3A00Z&se=2026-11-29T06%3A42%3A00Z&sr=b&sp=r&sig=5Gs%2FOXqP3zY00lgciu4BZjDV5QjTDIx7fgnfdz6Pu24%3D",
|
| 59 |
"https://hackrx.blob.core.windows.net/assets/UNI%20GROUP%20HEALTH%20INSURANCE%20POLICY%20-%20UIIHLGP26043V022526%201.pdf?sv=2023-01-03&spr=https&st=2025-07-31T17%3A06%3A03Z&se=2026-08-01T17%3A06%3A00Z&sr=b&sp=r&sig=wLlooaThgRx91i2z4WaeggT0qnuUUEzIUKj42GsvMfg%3D",
|
| 60 |
"https://hackrx.blob.core.windows.net/assets/Happy%20Family%20Floater%20-%202024%20OICHLIP25046V062425%201.pdf?sv=2023-01-03&spr=https&st=2025-07-31T17%3A24%3A30Z&se=2026-08-01T17%3A24%3A00Z&sr=b&sp=r&sig=VNMTTQUjdXGYb2F4Di4P0zNvmM2rTBoEHr%2BnkUXIqpQ%3D",
|
| 61 |
+
"https://dn790007.ca.archive.org/0/items/newtonspmathema00newtrich/newtonspmathema00newtrich.pdf",
|
| 62 |
+
"https://hackrx.blob.core.windows.net/assets/principia_newton.pdf?sv=2023-01-03&st=2025-07-28T07%3A20%3A32Z&se=2026-07-29T07%3A20%3A00Z&sr=b&sp=r&sig=V5I1QYyigoxeUMbnUKsdEaST99F5%2FDfo7wpKg9XXF5w%3D"
|
| 63 |
]
|
| 64 |
|
| 65 |
|
|
|
|
| 105 |
max_output_tokens=300
|
| 106 |
)
|
| 107 |
ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
|
| 108 |
+
**Role**: You are an expert assistant in insurance, legal compliance, human resources, and contract management.
|
| 109 |
+
Your job is to answer using ONLY the provided context, in a way that feels natural, clear, and helpful — as if speaking to a client.
|
| 110 |
+
Do not invent or assume information that is not explicitly stated in the context.
|
| 111 |
+
If the answer is not found in the context, politely state that it is unavailable.
|
| 112 |
+
|
| 113 |
+
**Tone & Style**:
|
| 114 |
+
- Be professional yet approachable.
|
| 115 |
+
- Use complete sentences and natural phrasing.
|
| 116 |
+
- Avoid legal jargon unless it is in the context.
|
| 117 |
+
- Keep answers concise but complete.
|
| 118 |
+
|
| 119 |
**Context**:
|
| 120 |
{context}
|
| 121 |
|
| 122 |
**Query**: {full_query}
|
| 123 |
|
| 124 |
**Response**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
"""
|
| 126 |
)
|
| 127 |
|
|
|
|
| 234 |
keyword_retriever = BM25Retriever.from_documents(chunks)
|
| 235 |
keyword_retriever.k = 8
|
| 236 |
# dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
|
| 237 |
+
ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.6, 0.4],search_kwargs={"k": 11})
|
| 238 |
### to make it faster we are now using our built reranker thats why commenting the code below
|
| 239 |
# compression_retriever = ContextualCompressionRetriever(
|
| 240 |
# base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]
|