Transformers
English
code
File size: 635 Bytes
bf27104
 
9819ce2
 
bf27104
 
 
 
9819ce2
 
bf27104
 
 
 
 
 
9819ce2
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from pydantic import BaseModel
from src.model_inference import predict
from src.utils import setup_logging, log_info, log_error

# Initialize FastAPI app
app = FastAPI()

# Set up logging
setup_logging()

# Define the input data model
class LogData(BaseModel):
    log: str

@app.post("/predict")
async def predict_route(data: LogData):
    try:
        # Perform prediction
        prediction = predict(data.log)
        log_info(f'Prediction: {prediction}')
        return {"prediction": prediction}
    except Exception as e:
        log_error(f'An error occurred: {e}')
        return {"error": str(e)}