File size: 1,449 Bytes
568efc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import numpy as np
import re
from datetime import datetime
import subprocess
from fairseq.models.transformer import TransformerModel
time_interval=0
st.title('Knowledge Distillation in Neural Machine Translation')
title = st.text_input('English Text', 'I welcome you to the demonstration.')

if st.button('En-Hi Teacher'):
	time_1 = datetime.now()
	#subprocess.run('source  ~/miniconda3/etc/profile.d/conda.sh && conda init bash')
	file1 = open("translation/input-files/flores/eng.devtest","w")
	file1.write(title)
	file1.close()
	subprocess.run('cd translation && bash -i translate-en-hi.sh && cd ..', shell=True)
	time_2 = datetime.now()
	time_interval = time_2 - time_1
	file1 = open("translation/output-translation/flores/test-flores.hi","r")
	st.write('Hindi Translation: ',file1.read())
	
	file1.close()
	st.write('Inference Time: ',time_interval)
	
if st.button('En-Hi Student'):
	#title = re.sub('([.,!?()])', r' \1 ', title)
	#title = re.sub('\s{2,}', ' ', title)
	time_1 = datetime.now()
	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')
	time_2 = datetime.now()
	time_interval = time_2 - time_1
	st.write('Hindi Translation: ',zh2en.translate([title.lower()])[0])
	st.write('Inference Time: ',time_interval)