coutant commited on
Commit
752db5c
1 Parent(s): 637f402

refactored layout using gradio blocks so as to have source and back translation together.

Browse files
Files changed (1) hide show
  1. app.py +40 -12
app.py CHANGED
@@ -10,19 +10,47 @@ def translate(text, model):
10
  return output
11
 
12
  def check(en):
 
 
13
  fr = translate(en, en_fr_model)
14
  en2 = translate(fr,fr_en_model)
15
  return fr,en2
16
 
17
- gr.Interface(
18
- fn=check,
19
- inputs = gr.Textbox(label="EN - original"),
20
- outputs = [ gr.Textbox(label="FR - target"), gr.Textbox(label="EN - back") ],
21
- title="Back translation : insights in target translation quality",
22
- description="Translating back to source language is one mean to measure the quality of the target translation. Can be useful when you need to check the translation to a language you hardly understand... The loop feedback may even guide you to rewrite original text enabling a better translation. Translations using Helsinki-NLP Opus MT models.",
23
- examples= [
24
- "Translating a language is a very complex problem and yet this Helsinki-NLP model does it both well and quickly, do you agree?",
25
- "Reverse translation, is the process of translating content from the target language back to its source language. The final outcome in English should match the original as closely as possible in a quality translation job."
26
- ],
27
- allow_flagging="never"
28
- ).launch(debug=True, enable_queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  return output
11
 
12
  def check(en):
13
+ if en is None:
14
+ return None,None
15
  fr = translate(en, en_fr_model)
16
  en2 = translate(fr,fr_en_model)
17
  return fr,en2
18
 
19
+ def clear():
20
+ return None,None,None
21
+
22
+ source=gr.Textbox(label="EN - original", value="") # delaying rendering enables to control layout order
23
+
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("# Back translation : insights in target translation quality")
26
+ gr.Markdown("Translating back to source language is one mean to measure the quality of the target translation. Can be useful when you need to check the translation to a language you hardly understand...")
27
+ gr.Markdown("The loop feedback may even guide you to rewrite original text enabling a better translation. Translations using Helsinki-NLP Opus MT models.")
28
+
29
+ examples= gr.Examples(
30
+ examples= [
31
+ "Translating a language is a very complex problem and yet this Helsinki-NLP model does it both well and quickly, do you agree?",
32
+ "Reverse translation, is the process of translating content from the target language back to its source language. The final outcome in English should match the original as closely as possible in a quality translation job."
33
+ ],
34
+ inputs= [ source ]
35
+ )
36
+ go_btn = gr.Button("Translate")
37
+ source.render()
38
+ en_back = gr.Textbox(label="EN - back")
39
+ target =gr.Textbox(label="FR - target")
40
+ go_btn.click( fn=check, inputs=[source], outputs= [target,en_back])
41
+ gr.Button("Clear").click( fn=clear, inputs=[], outputs= [source, en_back,target] )
42
+
43
+ demo.launch(debug=True, enable_queue=True)
44
+
45
+ # gr.Interface(
46
+ # fn=check,
47
+ # inputs = gr.Textbox(label="EN - original"),
48
+ # outputs = [ gr.Textbox(label="FR - target"), gr.Textbox(label="EN - back") ],
49
+ # title="Back translation : insights in target translation quality",
50
+ # description="Translating back to source language is one mean to measure the quality of the target translation. Can be useful when you need to check the translation to a language you hardly understand... The loop feedback may even guide you to rewrite original text enabling a better translation. Translations using Helsinki-NLP Opus MT models.",
51
+ # examples= [
52
+ # "Translating a language is a very complex problem and yet this Helsinki-NLP model does it both well and quickly, do you agree?",
53
+ # "Reverse translation, is the process of translating content from the target language back to its source language. The final outcome in English should match the original as closely as possible in a quality translation job."
54
+ # ],
55
+ # allow_flagging="never"
56
+ # ).launch(debug=True, enable_queue=True)