Update app/routes/summarize.py
Browse files- app/routes/summarize.py +25 -13
app/routes/summarize.py
CHANGED
|
@@ -1,13 +1,25 @@
|
|
| 1 |
-
from fastapi import APIRouter, Request
|
| 2 |
-
from app.core.summarizer import get_summary
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from app.core.summarizer import get_summary
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
@router.post("/summarize")
|
| 8 |
+
async def summarize(request: Request):
|
| 9 |
+
try:
|
| 10 |
+
data = await request.json()
|
| 11 |
+
text = data.get("text", "")
|
| 12 |
+
logging.info(f"Received text of length {len(text)}")
|
| 13 |
+
|
| 14 |
+
if not text or len(text.strip()) < 30:
|
| 15 |
+
logging.warning("Text too short to summarize.")
|
| 16 |
+
return {"summary": "Text too short to summarize."}
|
| 17 |
+
|
| 18 |
+
summary = get_summary(text)
|
| 19 |
+
logging.info("Summary generated successfully.")
|
| 20 |
+
logging.info(f"Summary: {summary[:250]}...") # Log first 250 chars
|
| 21 |
+
return {"summary": summary}
|
| 22 |
+
|
| 23 |
+
except Exception as e:
|
| 24 |
+
logging.exception("Error in /summarize route")
|
| 25 |
+
return {"error": str(e)}
|