Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
print("🔥 app.py
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import re
|
|
@@ -22,7 +22,7 @@ from langchain.retrievers import EnsembleRetriever, ContextualCompressionRetriev
|
|
| 22 |
from langchain.retrievers.document_compressors import CrossEncoderReranker
|
| 23 |
from langchain_community.cross_encoders import HuggingFaceCrossEncoder
|
| 24 |
from langchain.prompts import PromptTemplate
|
| 25 |
-
|
| 26 |
|
| 27 |
# Load environment variables
|
| 28 |
load_dotenv()
|
|
@@ -93,7 +93,7 @@ Else:
|
|
| 93 |
yield
|
| 94 |
print("🧹 Cleaning up.")
|
| 95 |
ml_models.clear()
|
| 96 |
-
|
| 97 |
# --- 2. FastAPI App Instance ---
|
| 98 |
# We pass the lifespan function to the FastAPI constructor
|
| 99 |
app = FastAPI(title="HackRX RAG Server", lifespan=lifespan)
|
|
@@ -107,6 +107,7 @@ def verify_api_key(authorization: str = Header(...)):
|
|
| 107 |
if token != TEAM_API_KEY:
|
| 108 |
raise HTTPException(status_code=403, detail="Invalid or missing API key")
|
| 109 |
|
|
|
|
| 110 |
# --- 4. Parsing Helper ---
|
| 111 |
def parse_llm_response(content: str) -> str:
|
| 112 |
try:
|
|
@@ -132,7 +133,7 @@ def parse_llm_response(content: str) -> str:
|
|
| 132 |
except Exception as e:
|
| 133 |
return f"An error occurred while processing the response: {str(e)}"
|
| 134 |
|
| 135 |
-
|
| 136 |
# --- 5. Main API Endpoint ---
|
| 137 |
@app.post("/api/v1/hackrx/run", response_model=RunResponse, dependencies=[Depends(verify_api_key)])
|
| 138 |
async def run_hackrx(req: RunRequest):
|
|
@@ -166,7 +167,7 @@ async def run_hackrx(req: RunRequest):
|
|
| 166 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 167 |
|
| 168 |
return JSONResponse({"answers": answers}, status_code=200)
|
| 169 |
-
|
| 170 |
@app.get("/", include_in_schema=False)
|
| 171 |
def root():
|
| 172 |
return {"message": "API is running. Go to /docs for documentation."}
|
|
|
|
| 1 |
+
print("🔥 app.py loaded1")
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import re
|
|
|
|
| 22 |
from langchain.retrievers.document_compressors import CrossEncoderReranker
|
| 23 |
from langchain_community.cross_encoders import HuggingFaceCrossEncoder
|
| 24 |
from langchain.prompts import PromptTemplate
|
| 25 |
+
print("🔥 app.py loaded2")
|
| 26 |
|
| 27 |
# Load environment variables
|
| 28 |
load_dotenv()
|
|
|
|
| 93 |
yield
|
| 94 |
print("🧹 Cleaning up.")
|
| 95 |
ml_models.clear()
|
| 96 |
+
print("🔥 app.py loaded1")
|
| 97 |
# --- 2. FastAPI App Instance ---
|
| 98 |
# We pass the lifespan function to the FastAPI constructor
|
| 99 |
app = FastAPI(title="HackRX RAG Server", lifespan=lifespan)
|
|
|
|
| 107 |
if token != TEAM_API_KEY:
|
| 108 |
raise HTTPException(status_code=403, detail="Invalid or missing API key")
|
| 109 |
|
| 110 |
+
print("🔥 app.py loaded3")
|
| 111 |
# --- 4. Parsing Helper ---
|
| 112 |
def parse_llm_response(content: str) -> str:
|
| 113 |
try:
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
return f"An error occurred while processing the response: {str(e)}"
|
| 135 |
|
| 136 |
+
print("🔥 app.py loaded4")
|
| 137 |
# --- 5. Main API Endpoint ---
|
| 138 |
@app.post("/api/v1/hackrx/run", response_model=RunResponse, dependencies=[Depends(verify_api_key)])
|
| 139 |
async def run_hackrx(req: RunRequest):
|
|
|
|
| 167 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 168 |
|
| 169 |
return JSONResponse({"answers": answers}, status_code=200)
|
| 170 |
+
print("🔥 app.py loaded5")
|
| 171 |
@app.get("/", include_in_schema=False)
|
| 172 |
def root():
|
| 173 |
return {"message": "API is running. Go to /docs for documentation."}
|