Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,25 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from
|
| 4 |
-
import
|
| 5 |
|
| 6 |
# Initialize FastAPI app
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
model = AutoModelForCausalLM.from_pretrained("canstralian/CyberAttackDetection")
|
| 12 |
|
| 13 |
# Define the input data model
|
| 14 |
class LogData(BaseModel):
|
| 15 |
log: str
|
| 16 |
|
| 17 |
@app.post("/predict")
|
| 18 |
-
async def
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
-
|
| 29 |
-
return {"prediction": prediction}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from src.model_inference import predict
|
| 4 |
+
from src.utils import setup_logging, log_info, log_error
|
| 5 |
|
| 6 |
# Initialize FastAPI app
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Set up logging
|
| 10 |
+
setup_logging()
|
|
|
|
| 11 |
|
| 12 |
# Define the input data model
|
| 13 |
class LogData(BaseModel):
|
| 14 |
log: str
|
| 15 |
|
| 16 |
@app.post("/predict")
|
| 17 |
+
async def predict_route(data: LogData):
|
| 18 |
+
try:
|
| 19 |
+
# Perform prediction
|
| 20 |
+
prediction = predict(data.log)
|
| 21 |
+
log_info(f'Prediction: {prediction}')
|
| 22 |
+
return {"prediction": prediction}
|
| 23 |
+
except Exception as e:
|
| 24 |
+
log_error(f'An error occurred: {e}')
|
| 25 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|