add translation of system answer
This commit is contained in:
parent
e9ffbd646f
commit
7bb36b5bac
17
Main.py
17
Main.py
@ -1,9 +1,24 @@
|
||||
import requests
|
||||
|
||||
from NaturalLanguageAnalyzer import NaturalLanguageAnalyzer
|
||||
from DialoguePolicy import DialoguePolicy
|
||||
from DialogueStateTracker import DialogueStateTracker
|
||||
from convlab.dialog_agent import PipelineAgent
|
||||
from MachineLearningNLG import MachineLearningNLG # Importujemy nowy komponent NLG
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = "chciałbym zarezerwować drogi hotel z parkingiem 1 stycznia w Warszawie w centrum"
|
||||
nlu = NaturalLanguageAnalyzer()
|
||||
@ -13,4 +28,4 @@ if __name__ == "__main__":
|
||||
|
||||
agent = PipelineAgent(nlu=nlu, dst=dst, policy=policy, nlg=nlg, name='sys')
|
||||
response = agent.response(text)
|
||||
print(response)
|
||||
print(translate_text(response))
|
||||
|
Loading…
Reference in New Issue
Block a user