Manu4082 commited on
Commit
944ee5d
·
1 Parent(s): 4a13dd9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from mtranslate import translate
3
+ import pandas as pd
4
+ import os
5
+ from gtts import gTTS
6
+ import base64
7
+ import pandas as pd
8
+ from transformers import pipeline,AutoTokenizer, AutoModelForSeq2SeqLM
9
+ import pickle
10
+ import torch
11
+
12
+ # Load a pretrained tokenizer for the source and target languages
13
+ tokenizer = AutoTokenizer.from_pretrained("KigenCHESS/marian-finetuned-kde4-en-to-fr")
14
+
15
+ # load the model
16
+ model = AutoModelForSeq2SeqLM.from_pretrained("KigenCHESS/marian-finetuned-kde4-en-to-fr", from_tf=True)
17
+
18
+ # Set up the translation pipeline using the loaded model
19
+ translator = pipeline("translation", model=model, tokenizer=tokenizer)
20
+
21
+ # layout
22
+ st.title("Language-Translation")
23
+ st.markdown("In Python 🐍 with Streamlit")
24
+ st.markdown("by DR Andrew Kipkebut")
25
+ inputtext = st.text_area("INPUT",height=200)
26
+
27
+ #the correct translation
28
+ speech_lang = {
29
+ "sw": "Swahili",
30
+ }
31
+
32
+ selected_lang = None
33
+ for lang_code, lang_name in speech_lang.items():
34
+ if st.button(lang_name):
35
+ selected_lang = lang_code
36
+ break
37
+
38
+ #to create two columns
39
+ c1,c2 = st.columns([4,3])
40
+
41
+ #I/0
42
+ if len(inputtext) > 0 :
43
+ try:
44
+ output = translator(inputtext)
45
+ translated_text = output[0]['translation_text']
46
+ with c1:
47
+ st.text_area("PREDICTED TRANSLATED TEXT", translated_text, height=200)
48
+
49
+ #the translation below is the correct one
50
+ output = translate(inputtext,selected_lang)
51
+ with c2:
52
+ st.text_area("CORRECT TRANSLATED TEXT",output,height=200)
53
+ except Exception as e:
54
+ st.error(e