Aeon-Avinash commited on
Commit
8553d28
1 Parent(s): 98fefd6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import torch
3
+ import gradio as gr
4
+ from lang_codes import get_language_code, get_language_list
5
+
6
+ text_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16)
7
+
8
+ def translate_text(text, source = "English", target = "German"):
9
+ src_code = get_language_code(source)
10
+ dest_code = get_language_code(target)
11
+ translation = text_translator(text,
12
+ src_lang=src_code,
13
+ tgt_lang=dest_code)
14
+ return translation[0]["translation_text"]
15
+
16
+ # translate_text("Hello Friends. How are you?", "German")
17
+
18
+ language_list = get_language_list()
19
+
20
+ gr.close_all()
21
+
22
+ demo = gr.Interface(
23
+ fn=translate_text,
24
+ inputs=[
25
+ gr.Textbox(label="Input text to Translate"),
26
+ gr.Dropdown(label="Select Input Language", choices=language_list, value="English"),
27
+ gr.Dropdown(label="Select Output Language", choices=language_list, value="German"),
28
+ ],
29
+ outputs=[
30
+ gr.Textbox(label="Translated text", lines=6)
31
+ ],
32
+ title="Multi Language Translator",
33
+ description="This App translates from any language to any langauge")
34
+ demo.launch()