Upload 12 files
Browse files- app/__init__.py +0 -0
- app/__pycache__/__init__.cpython-311.pyc +0 -0
- app/__pycache__/main.cpython-311.pyc +0 -0
- app/core/__init__.py +0 -0
- app/core/__pycache__/__init__.cpython-311.pyc +0 -0
- app/core/__pycache__/summarizer.cpython-311.pyc +0 -0
- app/core/summarizer.py +7 -0
- app/main.py +18 -0
- app/routes/__init__.py +0 -0
- app/routes/__pycache__/__init__.cpython-311.pyc +0 -0
- app/routes/__pycache__/summarize.cpython-311.pyc +0 -0
- app/routes/summarize.py +13 -0
app/__init__.py
ADDED
|
File without changes
|
app/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (196 Bytes). View file
|
|
|
app/__pycache__/main.cpython-311.pyc
ADDED
|
Binary file (689 Bytes). View file
|
|
|
app/core/__init__.py
ADDED
|
File without changes
|
app/core/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (201 Bytes). View file
|
|
|
app/core/__pycache__/summarizer.cpython-311.pyc
ADDED
|
Binary file (717 Bytes). View file
|
|
|
app/core/summarizer.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 4 |
+
|
| 5 |
+
def get_summary(text: str) -> str:
|
| 6 |
+
result = summarizer(text, max_length=150, min_length=30, do_sample=False)
|
| 7 |
+
return result[0]["summary_text"]
|
app/main.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from app.routes import summarize
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
app.add_middleware(
|
| 8 |
+
CORSMiddleware,
|
| 9 |
+
allow_origins=["*"],
|
| 10 |
+
allow_methods=["*"],
|
| 11 |
+
allow_headers=["*"],
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
@app.get("/")
|
| 15 |
+
def read_root():
|
| 16 |
+
return {"message": "AutoTLDR backend is running"}
|
| 17 |
+
|
| 18 |
+
app.include_router(summarize.router)
|
app/routes/__init__.py
ADDED
|
File without changes
|
app/routes/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (203 Bytes). View file
|
|
|
app/routes/__pycache__/summarize.cpython-311.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|
app/routes/summarize.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from app.core.summarizer import get_summary
|
| 3 |
+
|
| 4 |
+
router = APIRouter()
|
| 5 |
+
|
| 6 |
+
@router.post("/summarize")
|
| 7 |
+
async def summarize(request: Request):
|
| 8 |
+
data = await request.json()
|
| 9 |
+
text = data.get("text", "")
|
| 10 |
+
if not text or len(text.strip()) < 30:
|
| 11 |
+
return {"summary": "Text too short to summarize."}
|
| 12 |
+
summary = get_summary(text)
|
| 13 |
+
return {"summary": summary}
|