Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# main.py
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
import onnxruntime as ort
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
session = ort.InferenceSession("model.onnx")
|
| 10 |
+
|
| 11 |
+
class ModelInput(BaseModel):
|
| 12 |
+
input_ids: list[int]
|
| 13 |
+
attention_mask: list[int]
|
| 14 |
+
|
| 15 |
+
@app.post("/predict")
|
| 16 |
+
def predict(data: ModelInput):
|
| 17 |
+
input_ids = np.array(data.input_ids, dtype=np.int64).reshape(1, -1)
|
| 18 |
+
attention_mask = np.array(data.attention_mask, dtype=np.int64).reshape(1, -1)
|
| 19 |
+
inputs = {
|
| 20 |
+
"input_ids": input_ids,
|
| 21 |
+
"attention_mask": attention_mask,
|
| 22 |
+
}
|
| 23 |
+
outputs = session.run(None, inputs)
|
| 24 |
+
return {"output": outputs}
|