flare / controllers /admin_controller.py
ciyidogan's picture
Update controllers/admin_controller.py
6d2594f verified
raw
history blame
820 Bytes
from fastapi import APIRouter
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from core import INTENT_MODELS
import json, os
router = APIRouter()
@router.post("/load_intent_model")
def load_intent_model(project_name: str, model_path: str):
try:
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path)
with open(os.path.join(model_path, "label2id.json")) as f:
label2id = json.load(f)
INTENT_MODELS[project_name] = {
"model": model,
"tokenizer": tokenizer,
"label2id": label2id
}
return {"status": "ok", "message": f"'{project_name}' intent modeli yüklendi."}
except Exception as e:
return {"error": str(e)}