File size: 1,035 Bytes
b876f00
 
1b4655e
d57b505
6afa36a
1b4655e
0433163
cdc5783
0433163
cdc5783
 
 
 
 
 
 
 
6afa36a
 
a680719
 
6afa36a
d57b505
cdc5783
d57b505
0433163
 
a680719
1b4655e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0917f84
1b4655e
ec0efe8
ed70e07
0dcccf6
 
 
1b4655e
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
45
46
47
48
49
50
51
52
53
54
from typing import List
from typing_extensions import TypedDict

from fastapi import FastAPI
from pydantic import BaseModel

from summary import summarize

KEY = 'J9l#K4wP5h@2'
app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}


class SummaryReq(BaseModel):
    key: str
    id: str
    text: str


@app.post("/summary/")
async def summary(request: SummaryReq):
    if request.key != KEY:
        return 'Unauthorized'
    return summarize(request.id, request.text)


class Page(TypedDict):
    id: str
    text: str


class SummariesReq(BaseModel):
    key: str
    pages: List[Page]


@app.post("/summaries/")
async def summaries(request: SummariesReq):
    if request.key != KEY:
        return 'Unauthorized'
    result = []
    print('process pages: ' + str(len(request.pages)))
    for page in request.pages:
        try:
            print(page['id'])
            result.append(await summarize(page['id'], page['text']))
        except Exception as e:
            print(e)
    return result