Spaces:
Sleeping
Sleeping
Kevin Wu
commited on
Commit
·
9875dc5
1
Parent(s):
5aee5e7
put in API
Browse files- reviewer/api.py +26 -3
reviewer/api.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException
|
| 4 |
from fastapi.responses import JSONResponse
|
|
|
|
| 5 |
|
| 6 |
from pathlib import Path
|
| 7 |
import tempfile
|
|
@@ -14,8 +15,30 @@ reviewer = PDFReviewer()
|
|
| 14 |
|
| 15 |
|
| 16 |
@app.post("/review")
|
| 17 |
-
async def review_pdf(
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
if file.content_type != "application/pdf":
|
| 20 |
raise HTTPException(status_code=400, detail="Only PDF files are supported")
|
| 21 |
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException, Query
|
| 4 |
from fastapi.responses import JSONResponse
|
| 5 |
+
from typing import Optional
|
| 6 |
|
| 7 |
from pathlib import Path
|
| 8 |
import tempfile
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
@app.post("/review")
|
| 18 |
+
async def review_pdf(
|
| 19 |
+
file: Optional[UploadFile] = File(None),
|
| 20 |
+
test: bool = Query(False, description="Return mock data for testing")
|
| 21 |
+
):
|
| 22 |
+
"""Upload a PDF file and return the structured review as JSON.
|
| 23 |
+
|
| 24 |
+
If test=true is passed as a query parameter, returns mock data without requiring a file.
|
| 25 |
+
"""
|
| 26 |
+
# Return mock data if test mode is enabled
|
| 27 |
+
if test:
|
| 28 |
+
return JSONResponse(content={
|
| 29 |
+
"contributions": "Test contribution summary",
|
| 30 |
+
"strengths": "- Test strength 1\n- Test strength 2",
|
| 31 |
+
"weaknesses": "- Test weakness 1\n- Test weakness 2",
|
| 32 |
+
"requested_changes": "- Test change 1\n- Test change 2",
|
| 33 |
+
"impact_concerns": "No concerns for test",
|
| 34 |
+
"claims_and_evidence": "yes",
|
| 35 |
+
"audience_interest": "yes"
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
# Normal operation - file is required
|
| 39 |
+
if not file:
|
| 40 |
+
raise HTTPException(status_code=400, detail="File is required when not in test mode")
|
| 41 |
+
|
| 42 |
if file.content_type != "application/pdf":
|
| 43 |
raise HTTPException(status_code=400, detail="Only PDF files are supported")
|
| 44 |
|