maxcasado commited on
Commit
fc94431
·
verified ·
1 Parent(s): 92e9fc9

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +18 -0
api.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # api.py
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from typing import List, Dict, Any
5
+ from model_utils import predict_proba
6
+
7
+ app = FastAPI(title="StackOverflow Tagger API")
8
+
9
+
10
+ class Query(BaseModel):
11
+ text: str
12
+ top_k: int = 10
13
+
14
+
15
+ @app.post("/predict")
16
+ def predict(q: Query) -> Dict[str, Any]:
17
+ tags = predict_proba(q.text, top_k=q.top_k)
18
+ return {"tags": tags}