from convlab.base_models.t5.nlu import T5NLU import requests def translate_text(text, target_language='en'): url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={}&dt=t&q={}'.format( target_language, text) response = requests.get(url) if response.status_code == 200: translated_text = response.json()[0][0][0] return translated_text else: return None class NaturalLanguageAnalyzer: info_dict = None def predict(self, text, context=None): # Inicjalizacja modelu NLU model_name = "ConvLab/t5-small-nlu-multiwoz21" nlu_model = T5NLU(speaker='user', context_window_size=0, model_name_or_path=model_name) # Automatyczne tłumaczenie na język angielski translated_input = translate_text(text) # Wygenerowanie odpowiedzi z modelu NLU nlu_output = nlu_model.predict(translated_input) return nlu_output def init_session(self): # Inicjalizacja sesji (jeśli konieczne) pass