2024-06-04 21:53:50 +02:00
|
|
|
import requests
|
|
|
|
|
2024-04-17 19:35:47 +02:00
|
|
|
from NaturalLanguageAnalyzer import NaturalLanguageAnalyzer
|
2024-04-21 10:09:03 +02:00
|
|
|
from DialoguePolicy import DialoguePolicy
|
2024-05-27 21:50:25 +02:00
|
|
|
from DialogueStateTracker import DialogueStateTracker
|
|
|
|
from convlab.dialog_agent import PipelineAgent
|
2024-06-03 22:36:02 +02:00
|
|
|
from MachineLearningNLG import MachineLearningNLG # Importujemy nowy komponent NLG
|
2024-04-17 19:35:47 +02:00
|
|
|
|
2024-06-04 21:53:50 +02:00
|
|
|
|
|
|
|
def translate_text(text, target_language='pl'):
|
|
|
|
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]
|
|
|
|
translated_text_joined = ''.join([sentence[0] for sentence in translated_text])
|
|
|
|
return translated_text_joined
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2024-04-17 19:35:47 +02:00
|
|
|
if __name__ == "__main__":
|
2024-05-27 21:50:25 +02:00
|
|
|
text = "chciałbym zarezerwować drogi hotel z parkingiem 1 stycznia w Warszawie w centrum"
|
|
|
|
nlu = NaturalLanguageAnalyzer()
|
|
|
|
dst = DialogueStateTracker()
|
|
|
|
policy = DialoguePolicy()
|
2024-06-04 00:38:14 +02:00
|
|
|
nlg = MachineLearningNLG()
|
2024-04-21 10:09:03 +02:00
|
|
|
|
2024-05-27 21:50:25 +02:00
|
|
|
agent = PipelineAgent(nlu=nlu, dst=dst, policy=policy, nlg=nlg, name='sys')
|
|
|
|
response = agent.response(text)
|
2024-06-04 21:53:50 +02:00
|
|
|
print(translate_text(response))
|