Spaces:
Sleeping
Sleeping
File size: 818 Bytes
56ff037 |
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 supervised_classifier import QuestionClassifier
import torch
import json
class IntelligentQuestionRouter:
def __init__(self):
self.classifier = QuestionClassifier()
self._initialize_json()
def _initialize_json(self):
with open("examples.json", "r", encoding="utf-8") as f:
self.examples = json.load(f)
def _get_examples(self, category):
return self.examples.get(category, self.examples["CLIENTES_CERO"])
def route_question(self, question: str):
try:
ml_category_id = self.classifier.predict(question)
return self._get_examples(ml_category_id)
except Exception as e:
print("Error in routing question:", e)
return self._get_examples("CLIENTES_CERO")
|