Spaces:
Sleeping
Sleeping
Commit ·
e9038be
1
Parent(s): 365daa1
Fast API Fix
Browse files
app.py
CHANGED
|
@@ -30,6 +30,8 @@ logger = logging.getLogger(__name__)
|
|
| 30 |
# Create FastAPI app for API endpoints
|
| 31 |
api_app = FastAPI(title="Enhanced Single Document QA API", description="Single document AI query system")
|
| 32 |
|
|
|
|
|
|
|
| 33 |
@api_app.post("/hackrx/run")
|
| 34 |
async def hackrx_run(
|
| 35 |
request: Request,
|
|
@@ -47,24 +49,29 @@ async def hackrx_run(
|
|
| 47 |
if not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):
|
| 48 |
return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})
|
| 49 |
|
| 50 |
-
#
|
| 51 |
if isinstance(documents, list):
|
| 52 |
document_url = documents[0]
|
| 53 |
else:
|
| 54 |
document_url = documents
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
if not doc_result.get("success"):
|
| 59 |
return JSONResponse(content={"error": doc_result.get("error")}, status_code=500)
|
| 60 |
|
| 61 |
-
# Answer questions
|
| 62 |
-
batch_result =
|
| 63 |
answers = batch_result.get("answers", [])
|
| 64 |
|
|
|
|
|
|
|
| 65 |
return JSONResponse(content={"answers": answers}, status_code=200)
|
| 66 |
|
| 67 |
except Exception as e:
|
|
|
|
| 68 |
logger.error(f"API Error: {str(e)}")
|
| 69 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 70 |
|
|
|
|
| 30 |
# Create FastAPI app for API endpoints
|
| 31 |
api_app = FastAPI(title="Enhanced Single Document QA API", description="Single document AI query system")
|
| 32 |
|
| 33 |
+
# Make sure you have: from some_module import hackathon_system, logger
|
| 34 |
+
|
| 35 |
@api_app.post("/hackrx/run")
|
| 36 |
async def hackrx_run(
|
| 37 |
request: Request,
|
|
|
|
| 49 |
if not isinstance(questions, list) or not all(isinstance(q, str) for q in questions):
|
| 50 |
return JSONResponse(status_code=400, content={"error": "'questions' must be a list of strings"})
|
| 51 |
|
| 52 |
+
# Kept this improved handling from your second version
|
| 53 |
if isinstance(documents, list):
|
| 54 |
document_url = documents[0]
|
| 55 |
else:
|
| 56 |
document_url = documents
|
| 57 |
|
| 58 |
+
# --- Start of Missing Logic from First Snippet ---
|
| 59 |
+
|
| 60 |
+
# ✅ Step 1: Process document (using the call from the first version)
|
| 61 |
+
doc_result = hackathon_system.process_document_efficiently(document_url)
|
| 62 |
if not doc_result.get("success"):
|
| 63 |
return JSONResponse(content={"error": doc_result.get("error")}, status_code=500)
|
| 64 |
|
| 65 |
+
# ✅ Step 2: Answer questions (using the call from the first version)
|
| 66 |
+
batch_result = hackathon_system.process_batch_queries(questions)
|
| 67 |
answers = batch_result.get("answers", [])
|
| 68 |
|
| 69 |
+
# --- End of Missing Logic ---
|
| 70 |
+
|
| 71 |
return JSONResponse(content={"answers": answers}, status_code=200)
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
+
# Kept the improved logging from your second version
|
| 75 |
logger.error(f"API Error: {str(e)}")
|
| 76 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 77 |
|