Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,23 @@ translation_model = MBartForConditionalGeneration.from_pretrained("facebook/mbar
|
|
33 |
translation_tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")
|
34 |
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
user_session_id = uuid.uuid4()
|
38 |
|
@@ -170,7 +187,7 @@ if prompt := st.chat_input("How can I help you today?"):
|
|
170 |
message_placeholder = st.empty()
|
171 |
full_response = ""
|
172 |
message_history = "\n".join(list(get_message_history())[-3:])
|
173 |
-
|
174 |
output = [result['result']]
|
175 |
|
176 |
def generate_pdf():
|
|
|
33 |
translation_tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")
|
34 |
|
35 |
|
36 |
+
def english_to_hindi(sentence):
|
37 |
+
translation_tokenizer.src_lang = "en_xx"
|
38 |
+
encoded_hi = translation_tokenizer(article_hi, return_tensors="pt")
|
39 |
+
generated_tokens = translation_model.generate(
|
40 |
+
**encoded_hi, forced_bos_token_id=translation_tokenizer.lang_code_to_id["hi_IN"] )
|
41 |
+
|
42 |
+
return (translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True))
|
43 |
+
|
44 |
+
|
45 |
+
def hindi_to_english(sentence):
|
46 |
+
translation_tokenizer.src_lang = "hi_IN"
|
47 |
+
encoded_hi = translation_tokenizer(article_hi, return_tensors="pt")
|
48 |
+
generated_tokens = translation_model.generate(
|
49 |
+
**encoded_hi, forced_bos_token_id=translation_tokenizer.lang_code_to_id["en_XX"] )
|
50 |
+
|
51 |
+
return (translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True))
|
52 |
+
|
53 |
|
54 |
user_session_id = uuid.uuid4()
|
55 |
|
|
|
187 |
message_placeholder = st.empty()
|
188 |
full_response = ""
|
189 |
message_history = "\n".join(list(get_message_history())[-3:])
|
190 |
+
result = qa_chain(hindi_to_english(prompt))
|
191 |
output = [result['result']]
|
192 |
|
193 |
def generate_pdf():
|