sohamchitimali commited on
Commit
3ae468e
·
1 Parent(s): ecb9212

Added Hugging Face WebHook Trigger Compatibility

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -35,16 +35,18 @@ api_app = FastAPI(title="HackRx API", description="AI-powered document query sys
35
  @api_app.post("/hackrx/run")
36
  async def hackrx_run(
37
  request: Request,
38
- authorization: str = Header(default=None)
 
39
  ):
40
  try:
41
- if not authorization:
42
- return JSONResponse(status_code=401, content={"error": "Missing Authorization header"})
 
43
 
44
- # Optional: Validate the Bearer token if needed
45
- # token_value = authorization.replace("Bearer ", "")
46
- # if token_value != EXPECTED_TOKEN:
47
- # return JSONResponse(status_code=403, content={"error": "Invalid token"})
48
 
49
  data = await request.json()
50
  document_url = data.get("documents")
@@ -56,12 +58,12 @@ async def hackrx_run(
56
  if not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):
57
  return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})
58
 
59
- # Step 1: Process document
60
  doc_result = hackathon_system.process_document_efficiently(document_url)
61
  if not doc_result.get("success"):
62
- return JSONResponse({"error": doc_result.get("error")}, status_code=500)
63
 
64
- # Step 2: Process questions
65
  batch_result = hackathon_system.process_batch_queries(questions)
66
  answers = batch_result.get("answers", [])
67
 
 
35
  @api_app.post("/hackrx/run")
36
  async def hackrx_run(
37
  request: Request,
38
+ authorization: Optional[str] = Header(default=None),
39
+ x_webhook_secret: Optional[str] = Header(default=None)
40
  ):
41
  try:
42
+ # ⚠️ You can optionally log headers for debugging
43
+ # print("Authorization:", authorization)
44
+ # print("Webhook secret:", x_webhook_secret)
45
 
46
+ # 🔐 Optional: Validate at least one of them if needed
47
+ # Example if you want:
48
+ # if not authorization and not x_webhook_secret:
49
+ # return JSONResponse(status_code=401, content={"error": "Missing authentication"})
50
 
51
  data = await request.json()
52
  document_url = data.get("documents")
 
58
  if not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):
59
  return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})
60
 
61
+ # Step 1: Process document
62
  doc_result = hackathon_system.process_document_efficiently(document_url)
63
  if not doc_result.get("success"):
64
+ return JSONResponse(content={"error": doc_result.get("error")}, status_code=500)
65
 
66
+ # Step 2: Answer questions
67
  batch_result = hackathon_system.process_batch_queries(questions)
68
  answers = batch_result.get("answers", [])
69