Spaces:
Sleeping
Sleeping
Create app.py
Browse filesCreates the translation from English Text to French. Uses the Google T5 Model.
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
Translate = pipeline("translation_en_to_fr", model="shashankheg/my_opus_books_model")
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
def QA(English_input):
|
9 |
+
result=Translate(English_input)
|
10 |
+
for i in result :
|
11 |
+
op=i['translation_text']
|
12 |
+
return op
|
13 |
+
|
14 |
+
js = """
|
15 |
+
function createGradioAnimation() {
|
16 |
+
var container = document.createElement('div');
|
17 |
+
container.id = 'gradio-animation';
|
18 |
+
container.style.fontSize = '2em';
|
19 |
+
container.style.fontWeight = 'bold';
|
20 |
+
container.style.textAlign = 'center';
|
21 |
+
container.style.marginBottom = '20px';
|
22 |
+
container.style.color='#d3dfe2';
|
23 |
+
container.style.padding = '10px';
|
24 |
+
container.style.borderRadius = '5px';
|
25 |
+
var text = 'Translation using Google T5';
|
26 |
+
for (var i = 0; i < text.length; i++) {
|
27 |
+
(function(i){
|
28 |
+
setTimeout(function(){
|
29 |
+
var letter = document.createElement('span');
|
30 |
+
letter.style.opacity = '0';
|
31 |
+
letter.style.transition = 'opacity 0.5s';
|
32 |
+
letter.innerText = text[i];
|
33 |
+
|
34 |
+
container.appendChild(letter);
|
35 |
+
|
36 |
+
setTimeout(function() {
|
37 |
+
letter.style.opacity = '3';
|
38 |
+
}, 50);
|
39 |
+
}, i * 250);
|
40 |
+
})(i);
|
41 |
+
}
|
42 |
+
|
43 |
+
var gradioContainer = document.querySelector('.gradio-container');
|
44 |
+
gradioContainer.insertBefore(container, gradioContainer.firstChild);
|
45 |
+
|
46 |
+
return 'Animation created';
|
47 |
+
}
|
48 |
+
"""
|
49 |
+
custom_css = """
|
50 |
+
body {
|
51 |
+
background-color: #d2d9db; /* Light blue background */
|
52 |
+
}
|
53 |
+
"""
|
54 |
+
|
55 |
+
with gr.Blocks(js=js,css=".gradio-container {background-color: #d2d9db}") as demo:
|
56 |
+
gr.HTML("<center><h1>🌍 Language Translator from English to French</h1></center>")
|
57 |
+
inp = gr.Textbox(label="English Text",placeholder="English Text here:")
|
58 |
+
out = gr.Textbox(label='French Translation')
|
59 |
+
theme=gr.themes.Soft()
|
60 |
+
inp.change(QA, inp, out)
|
61 |
+
|
62 |
+
demo.launch()
|