-
Notifications
You must be signed in to change notification settings - Fork 5
/
chat_settings.py
54 lines (45 loc) · 1.56 KB
/
chat_settings.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 4 13:41:35 2019
@author: Danish
"""
"""
ChatSettings class
"""
import copy
from googletrans import Translator
t = Translator()
class ChatSettings(object):
"""Contains settings for a chat session.
"""
def __init__(self, model_hparams, inference_hparams):
"""
Args:
inference_hparams: the loaded InferenceHparams instance to use as default for this chat session
"""
self.show_question_context = False
self.show_all_beams = False
self.enable_auto_punctuation = True
self.model_hparams = None
self.inference_hparams = None
self._default_model_hparams = model_hparams
self._default_inference_hparams = inference_hparams
self.reset_to_defaults()
def reset_to_defaults(self):
"""Reset all settings to defaults
"""
self.show_question_context = False
self.show_all_beams = False
self.enable_auto_punctuation = True
self.model_hparams = copy.copy(self._default_model_hparams)
self.inference_hparams = copy.copy(self._default_inference_hparams)
def To_query(query):
question = t.translate([query], dest='en')
for get_question in question:
t_question=get_question.text
return t_question
def To_answer(reply):
answer = t.translate([reply], dest='ur')
for get_answer in answer:
t_answer=get_answer.text
return t_answer