Spaces:
Paused
Paused
Update intent_utils.py
Browse files- intent_utils.py +8 -12
intent_utils.py
CHANGED
@@ -14,16 +14,16 @@ from transformers import (
|
|
14 |
AutoConfig,
|
15 |
)
|
16 |
from log import log
|
17 |
-
from core import
|
18 |
|
19 |
async def detect_intent(text, project_name):
|
20 |
-
|
21 |
-
if not
|
22 |
raise Exception(f"'{project_name}' için intent modeli yüklenmemiş.")
|
23 |
|
24 |
-
tokenizer =
|
25 |
-
model =
|
26 |
-
label2id =
|
27 |
|
28 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
29 |
outputs = model(**inputs)
|
@@ -96,17 +96,13 @@ def background_training(project_name, intents, model_id, output_path, confidence
|
|
96 |
if accuracy < confidence_threshold or total < 5:
|
97 |
log(f"⚠️ Yetersiz performanslı intent: '{intent_name}' — Doğruluk: {accuracy:.2f}, Örnek: {total}")
|
98 |
|
|
|
99 |
model.save_pretrained(output_path)
|
100 |
tokenizer.save_pretrained(output_path)
|
101 |
with open(os.path.join(output_path, "label2id.json"), "w") as f:
|
102 |
json.dump(label2id, f)
|
103 |
|
104 |
-
|
105 |
-
"model": model,
|
106 |
-
"tokenizer": tokenizer,
|
107 |
-
"label2id": label2id,
|
108 |
-
}
|
109 |
-
log(f"✅ Intent eğitimi tamamlandı ve '{project_name}' modeli yüklendi.")
|
110 |
|
111 |
except Exception as e:
|
112 |
log(f"❌ Intent eğitimi hatası: {e}")
|
|
|
14 |
AutoConfig,
|
15 |
)
|
16 |
from log import log
|
17 |
+
from core import llm_models
|
18 |
|
19 |
async def detect_intent(text, project_name):
|
20 |
+
llm_model_instance = llm_models.get(project_name)
|
21 |
+
if not llm_model_instance or not llm_model_instance.intent_model:
|
22 |
raise Exception(f"'{project_name}' için intent modeli yüklenmemiş.")
|
23 |
|
24 |
+
tokenizer = llm_model_instance.intent_tokenizer
|
25 |
+
model = llm_model_instance.intent_model
|
26 |
+
label2id = llm_model_instance.intent_label2id
|
27 |
|
28 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
29 |
outputs = model(**inputs)
|
|
|
96 |
if accuracy < confidence_threshold or total < 5:
|
97 |
log(f"⚠️ Yetersiz performanslı intent: '{intent_name}' — Doğruluk: {accuracy:.2f}, Örnek: {total}")
|
98 |
|
99 |
+
# Eğitim sonrası model ve tokenizer'ı diske kaydet
|
100 |
model.save_pretrained(output_path)
|
101 |
tokenizer.save_pretrained(output_path)
|
102 |
with open(os.path.join(output_path, "label2id.json"), "w") as f:
|
103 |
json.dump(label2id, f)
|
104 |
|
105 |
+
log(f"✅ Intent eğitimi tamamlandı ve '{project_name}' için model disk üzerinde hazır.")
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
except Exception as e:
|
108 |
log(f"❌ Intent eğitimi hatası: {e}")
|