Asanaly commited on
Update main.py
Browse files
main.py
CHANGED
|
@@ -25,4 +25,23 @@ async def root():
|
|
| 25 |
return FileResponse("index.html")
|
| 26 |
|
| 27 |
# TEXT summarization
|
| 28 |
-
@app.post("/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return FileResponse("index.html")
|
| 26 |
|
| 27 |
# TEXT summarization
|
| 28 |
+
@app.post("/summarize/text")
|
| 29 |
+
async def summarize_text(data: dict):
|
| 30 |
+
text = data.get("text", "")
|
| 31 |
+
if not text.strip():
|
| 32 |
+
return {"summary": "No text provided."}
|
| 33 |
+
|
| 34 |
+
summary = generate_summary(text)
|
| 35 |
+
return {"summary": summary}
|
| 36 |
+
|
| 37 |
+
# PDF summarization
|
| 38 |
+
@app.post("/summarize/pdf")
|
| 39 |
+
async def summarize_pdf(file: UploadFile = File(...)):
|
| 40 |
+
pdf_bytes = await file.read()
|
| 41 |
+
text = extract_text_from_pdf(pdf_bytes)
|
| 42 |
+
|
| 43 |
+
if not text.strip():
|
| 44 |
+
return {"summary": "PDF is empty or could not be processed."}
|
| 45 |
+
|
| 46 |
+
summary = generate_summary(text)
|
| 47 |
+
return {"summary": summary}
|