spacesedan commited on
Commit
20dbd9d
·
1 Parent(s): b0c97d8

feat: returning post_id

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -7,14 +7,20 @@ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
7
 
8
  class SummarizationRequest(BaseModel):
9
  inputs: str
 
10
 
11
- @app.post("/summarize")
 
 
 
 
12
  async def summarize_text(request: SummarizationRequest):
13
  input_length = len(request.inputs.split())
14
  max_length = max(50, int(input_length * 0.5))
15
  min_length = max(20, int(input_length * 0.2))
 
16
  summary = summarizer(request.inputs, max_length=max_length, min_length=min_length, do_sample=False)
17
- return {"summary": summary[0]["summary_text"]}
18
 
19
  @app.get("/")
20
  def greet_json():
 
7
 
8
  class SummarizationRequest(BaseModel):
9
  inputs: str
10
+ post_id: str
11
 
12
+ class SummarizationResponse(BaseModel):
13
+ post_id: str
14
+ summary: str
15
+
16
+ @app.post("/summarize", response_model=SummarizationResponse)
17
  async def summarize_text(request: SummarizationRequest):
18
  input_length = len(request.inputs.split())
19
  max_length = max(50, int(input_length * 0.5))
20
  min_length = max(20, int(input_length * 0.2))
21
+
22
  summary = summarizer(request.inputs, max_length=max_length, min_length=min_length, do_sample=False)
23
+ return {"post_id": request.post_id, "summary": summary[0]["summary_text"]}
24
 
25
  @app.get("/")
26
  def greet_json():