-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
39 lines (24 loc) · 744 Bytes
/
Copy pathapi.py
File metadata and controls
39 lines (24 loc) · 744 Bytes
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
from typing import Optional, List
from fastapi import FastAPI
from pydantic import BaseModel
from get_tags import predict
app = FastAPI()
class Text(BaseModel):
title: str
body: str
class Texts(BaseModel):
title: List[str]
body: List[str]
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/get_tags_single")
def read_item(text: Text):
""" returns tag predictions for single pair of text and body """
predictions = predict([[text.title], [text.body]])
return predictions
@app.post("/get_tags_mutliple")
def read_item(texts: Texts):
""" returns tag predictions for multiple pairs of text and body """
predictions = predict([texts.title, texts.body])
return predictions