-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (38 loc) · 1.47 KB
/
main.py
File metadata and controls
44 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# main.py
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel, Field
from summarizer.pipeline import SummarizationPipeline
# Define the request body model for data validation
class SummarizationRequest(BaseModel):
documents: list[str]
num_clusters: int = Field(
default=3,
gt=1,
le=10,
description="Number of topic clusters to find (2-10)."
)
# Initialize the FastAPI app
app = FastAPI(
title="Suvidha Multi-Document Summarizer API",
description="An API that summarizes multiple documents using a hybrid extractive-abstractive approach.",
version="1.0.0",
)
# --- CRITICAL STEP ---
# Load the pipeline once when the app starts.
# This avoids reloading the heavy models on every request.
summarizer_pipeline = SummarizationPipeline()
# --- END CRITICAL STEP ---
# Define the API endpoint
@app.post("/summarize/", tags=["Summarization"])
async def summarize(request: SummarizationRequest):
"""
Receives a list of documents and returns a single summary.
"""
summary = summarizer_pipeline.run(documents=request.documents,
num_clusters=request.num_clusters
)
return {"summary": summary}
# Mount the 'static' directory to serve our frontend files
# This line makes it so visiting the root URL serves index.html
app.mount("/", StaticFiles(directory="static", html=True), name="static")