File size: 820 Bytes
6d2594f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)}