Spaces:
Paused
Paused
from fastapi import APIRouter | |
from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
from core import INTENT_MODELS | |
import json, os | |
router = APIRouter() | |
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)} | |