File size: 1,497 Bytes
944ee5d
 
 
 
 
 
 
 
9ea5e30
944ee5d
 
9ea5e30
944ee5d
 
9ea5e30
944ee5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ea5e30
944ee5d
 
 
 
481499c
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
import streamlit as st
from mtranslate import translate
import pandas as pd
import os
from gtts import gTTS
import base64
import pandas as pd
from transformers import pipeline,AutoTokenizer, AutoModelForSeq2SeqLM


# Load a pretrained tokenizer for the source and target languages
tokenizer = AutoTokenizer.from_pretrained("KigenCHESS/fine_tuned_eng-sw")

# load the model 
model = AutoModelForSeq2SeqLM.from_pretrained("KigenCHESS/fine_tuned_eng-sw", from_tf=True)

# Set up the translation pipeline using the loaded model
translator = pipeline("translation", model=model, tokenizer=tokenizer)

# layout
st.title("Language-Translation")
st.markdown("In Python 🐍 with Streamlit")
st.markdown("by DR Andrew Kipkebut")
inputtext = st.text_area("INPUT",height=200)

#the correct translation 
speech_lang = {
    "sw": "Swahili",
}

selected_lang = None
for lang_code, lang_name in speech_lang.items():
    if st.button(lang_name):
        selected_lang = lang_code
        break

#to create two columns 
c1,c2 = st.columns([4,3])

#I/0
if len(inputtext) > 0 :
    try:
        output = translator(inputtext)
        translated_text = output[0]['translation_text']
        with c1:
            st.text_area("PREDICTED TRANSLATED TEXT", translated_text, height=200)

        #the translation below is the correct 
        output = translate(inputtext,selected_lang)
        with c2:
            st.text_area("CORRECT TRANSLATED TEXT",output,height=200)
    except Exception as e:
        st.error(e)