File size: 1,032 Bytes
b876f00
 
1b4655e
d57b505
6afa36a
1b4655e
0433163
cdc5783
0433163
cdc5783
 
 
 
 
 
 
 
6afa36a
 
a680719
 
6afa36a
d57b505
cdc5783
d57b505
0433163
 
a680719
1b4655e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a7a102
 
1b4655e
4a7a102
 
ec0efe8
 
 
 
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
55
56
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('==============1')
    print(request.pages)
    for page in request.pages:
        print('==============2')
        print(page)
        try:
            result.append(await summarize(page.id, page.text))
        except:
            pass
    return result