Lekha Vulavala commited on
Commit
87df893
1 Parent(s): 1f05fa7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -46
app.py CHANGED
@@ -1,46 +1,46 @@
1
- import gradio as gr
2
- import torch
3
-
4
- from translate import Translator
5
-
6
- # https://medium.com/analytics-vidhya/make-a-translate-app-with-huggingface-transformers-ce9203f84c79
7
- # https://huggingface.co/docs/transformers/en/model_doc/mbart
8
- title = "Translation Chatbot"
9
- description = "A simple implementation of translating one language to another"
10
- examples = [["UN Chief Says There Is No Military Solution in Syria","en_XX","ja_XX"]]
11
-
12
- translator_obj = Translator()
13
-
14
- def translate_sentence(sentence):
15
- return pipe(f'<-ja2zh-> {sentence}')[0]['translation_text']
16
-
17
- def predict(input,
18
- history=[],
19
- original_language="en_XX",
20
- translated_language="ro_RO"):
21
- response = translator_obj.translate(input, original_language, translated_language)
22
- history.append((input, response))
23
- return history, history
24
-
25
- if __name__ == "__main__":
26
- gr.Interface(
27
- fn=predict,
28
- title=title,
29
- description=description,
30
- examples=examples,
31
- inputs=[
32
- gr.Textbox(),
33
- "state",
34
- gr.Dropdown(
35
- [("English","en_XX"), ("French","fr_XX"), ("German","de_DE"), ("Japanese","ja_XX"), ("Russian","ru_RU")], value="en_XX", label="Input Language", info="Choose the language the input text is in."
36
- ),
37
- gr.Dropdown(
38
- [("French","fr_XX"), ("German","de_DE"), ("Japanese","ja_XX"), ("Russian","ru_RU"), ("English","en_XX")], value="fr_XX", label="Language to translate to", info="Choose the language to convert the text to."
39
- )
40
- ],
41
- outputs=[
42
- gr.Chatbot(),
43
- "state"
44
- ],
45
- theme='earneleh/paris',
46
- ).launch()
 
1
+ import gradio as gr
2
+ import torch
3
+
4
+ from translate import Translator
5
+
6
+ # https://medium.com/analytics-vidhya/make-a-translate-app-with-huggingface-transformers-ce9203f84c79
7
+ # https://huggingface.co/docs/transformers/en/model_doc/mbart
8
+ title = "Translation Chatbot"
9
+ description = "A simple implementation of translating one language to another"
10
+ examples = [["UN Chief Says There Is No Military Solution in Syria","en_XX","ja_XX"]]
11
+
12
+ translator_obj = Translator()
13
+
14
+ def translate_sentence(sentence):
15
+ return pipe(f'<-ja2zh-> {sentence}')[0]['translation_text']
16
+
17
+ def predict(input,
18
+ history=[],
19
+ original_language="en_XX",
20
+ translated_language="ro_RO"):
21
+ response = translator_obj.translate(input, original_language, translated_language)
22
+ history.append((input, response))
23
+ return history, history
24
+
25
+ if __name__ == "__main__":
26
+ gr.Interface(
27
+ fn=predict,
28
+ title=title,
29
+ description=description,
30
+ examples=examples,
31
+ inputs=[
32
+ gr.Textbox(),
33
+ "state",
34
+ gr.Dropdown(
35
+ [("English","en_XX"), ("French","fr_XX"), ("German","de_DE"), ("Japanese","ja_XX"), ("Russian","ru_RU")], value="en_XX", label="Input Language", info="Choose the language the input text is in."
36
+ ),
37
+ gr.Dropdown(
38
+ [("French","fr_XX"), ("German","de_DE"), ("Japanese","ja_XX"), ("Russian","ru_RU"), ("English","en_XX")], value="fr_XX", label="Output Language", info="Choose the language to convert the text to."
39
+ )
40
+ ],
41
+ outputs=[
42
+ gr.Chatbot(),
43
+ "state"
44
+ ],
45
+ theme='earneleh/paris',
46
+ ).launch()