File size: 777 Bytes
0234723
48d759b
0234723
 
 
48d759b
0234723
 
 
48d759b
0234723
 
 
 
 
 
 
48d759b
 
 
 
 
 
 
 
 
 
 
0234723
2a1882c
0234723
48d759b
 
 
 
 
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
import pickle
from typing import List

import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

# Load model and encoder
with open("model.pkl", "rb") as f:
    model = pickle.load(f)

with open("label_encoder.pkl", "rb") as f:
    le = pickle.load(f)


class EmbeddingInput(BaseModel):
    embedding: List[float]


class PredictionOutput(BaseModel):
    result: str


@app.post("/predict", response_model=PredictionOutput)
def predict(data: EmbeddingInput):
    embedding = np.array(data.embedding).reshape(1, -1)
    pred = model.predict(embedding)
    pred_class = le.inverse_transform(pred)[0]
    return {"result": pred_class}


@app.get("/")
def read_root():
    return {"message": "OpenMP Loop Classifier API", "status": "running"}