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 | |
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)} | |