-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
45 lines (36 loc) · 1.05 KB
/
main.py
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from infill import INFILL
class Message(BaseModel):
input: str
output: str = None
app = FastAPI()
infill = INFILL()
origins = [
"http://localhost",
"http://localhost:3000",
"http://127.0.0.1:3000"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["POST"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"Hello": "Javier"}
@app.post("/infill_sentence/")
async def infill_sentence(message: Message):
message.output = str(infill.infilling_sentence(message.input))
return {"output": message.output}
@app.post("/infill_word/")
async def infill_word(message: Message):
message.output = str(infill.infilling_word(message.input))
return {"output": message.output}
@app.post("/infill_ngram/")
async def infill_ngram(message: Message):
message.output = str(infill.infilling_ngram(message.input))
return {"output": message.output}