Sakharam Gawade
commited on
Commit
•
568efc8
1
Parent(s):
f9362f2
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import re
|
5 |
+
from datetime import datetime
|
6 |
+
import subprocess
|
7 |
+
from fairseq.models.transformer import TransformerModel
|
8 |
+
time_interval=0
|
9 |
+
st.title('Knowledge Distillation in Neural Machine Translation')
|
10 |
+
title = st.text_input('English Text', 'I welcome you to the demonstration.')
|
11 |
+
|
12 |
+
if st.button('En-Hi Teacher'):
|
13 |
+
time_1 = datetime.now()
|
14 |
+
#subprocess.run('source ~/miniconda3/etc/profile.d/conda.sh && conda init bash')
|
15 |
+
file1 = open("translation/input-files/flores/eng.devtest","w")
|
16 |
+
file1.write(title)
|
17 |
+
file1.close()
|
18 |
+
subprocess.run('cd translation && bash -i translate-en-hi.sh && cd ..', shell=True)
|
19 |
+
time_2 = datetime.now()
|
20 |
+
time_interval = time_2 - time_1
|
21 |
+
file1 = open("translation/output-translation/flores/test-flores.hi","r")
|
22 |
+
st.write('Hindi Translation: ',file1.read())
|
23 |
+
|
24 |
+
file1.close()
|
25 |
+
st.write('Inference Time: ',time_interval)
|
26 |
+
|
27 |
+
if st.button('En-Hi Student'):
|
28 |
+
#title = re.sub('([.,!?()])', r' \1 ', title)
|
29 |
+
#title = re.sub('\s{2,}', ' ', title)
|
30 |
+
time_1 = datetime.now()
|
31 |
+
zh2en = TransformerModel.from_pretrained('Student_en_hi/out_distill/tokenized.en-hi/', checkpoint_file='../../checkpoint_use.pt',bpe='subword_nmt', bpe_codes='/home/sakharam/RnD/translation/en-hi/bpe-codes/codes.en',tokenizer='moses')
|
32 |
+
time_2 = datetime.now()
|
33 |
+
time_interval = time_2 - time_1
|
34 |
+
st.write('Hindi Translation: ',zh2en.translate([title.lower()])[0])
|
35 |
+
st.write('Inference Time: ',time_interval)
|