|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
import torch |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("canstralian/CyberAttackDetection") |
|
model = AutoModelForCausalLM.from_pretrained("canstralian/CyberAttackDetection") |
|
|
|
|
|
class LogData(BaseModel): |
|
log: str |
|
|
|
@app.post("/predict") |
|
async def predict(data: LogData): |
|
|
|
inputs = tokenizer(data.log, return_tensors="pt") |
|
|
|
|
|
with torch.no_grad(): |
|
outputs = model.generate(**inputs) |
|
|
|
|
|
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
return {"prediction": prediction} |
|
|