Spaces:
Sleeping
Sleeping
Commit ·
3ae468e
1
Parent(s): ecb9212
Added Hugging Face WebHook Trigger Compatibility
Browse files34 unmodified lines353637383940414243444546474849505 unmodified lines56575859606162636465666734 unmodified lines@api_app.post("/hackrx/run")async def hackrx_run(request: Request,authorization: str = Header(default=None)):try:if not authorization:return JSONResponse(status_code=401, content={"error": "Missing Authorization header"})# Optional: Validate the Bearer token if needed# token_value = authorization.replace("Bearer ", "")# if token_value != EXPECTED_TOKEN:# return JSONResponse(status_code=403, content={"error": "Invalid token"})data = await request.json()document_url = data.get("documents")5 unmodified linesif not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})# Step 1: Process documentdoc_result = hackathon_system.process_document_efficiently(document_url)if not doc_result.get("success"):return JSONResponse({"error": doc_result.get("error")}, status_code=500)# Step 2: Process questionsbatch_result = hackathon_system.process_batch_queries(questions)answers = batch_result.get("answers", [])34 unmodified lines3536373839404142434445464748495051525 unmodified lines58596061626364656667686934 unmodified lines@api_app.post("/hackrx/run")async def hackrx_run(request: Request,authorization: Optional[str] = Header(default=None),x_webhook_secret: Optional[str] = Header(default=None)):try:# ⚠️ You can optionally log headers for debugging# print("Authorization:", authorization)# print("Webhook secret:", x_webhook_secret)# 🔐 Optional: Validate at least one of them if needed# Example if you want:# if not authorization and not x_webhook_secret:# return JSONResponse(status_code=401, content={"error": "Missing authentication"})data = await request.json()document_url = data.get("documents")5 unmodified linesif not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})# ✅ Step 1: Process documentdoc_result = hackathon_system.process_document_efficiently(document_url)if not doc_result.get("success"):return JSONResponse(content={"error": doc_result.get("error")}, status_code=500)# ✅ Step 2: Answer questionsbatch_result = hackathon_system.process_batch_queries(questions)answers = batch_result.get("answers", [])
app.py+12-10