Stephan Arrington commited on
Commit
72e077d
1 Parent(s): 2a918d4

initial commit of a translation app

Browse files
Files changed (1) hide show
  1. app.py +42 -4
app.py CHANGED
@@ -1,7 +1,45 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
  import gradio as gr
2
 
3
+ # Import the pipeline
4
+ from transformers import pipeline
5
+
6
+ # Define the pipeline
7
+ # Note: This pipeline is hosted on the Hugging Face model hub
8
+ # https://huggingface.co/Helsinki-NLP/opus-mt-en-he
9
+ # You can replace this with any other translation pipeline
10
+ # https://huggingface.co/models?filter=translation
11
+ pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-he")
12
+
13
+ # Define a pipeline for reverse translation
14
+ # Note: This pipeline is hosted on the Hugging Face model hub
15
+ # https://huggingface.co/Helsinki-NLP/opus-mt-he-en
16
+ # You can replace this with any other translation pipeline
17
+ # https://huggingface.co/models?filter=translation
18
+ pipe_reverse = pipeline("translation", model="Helsinki-NLP/opus-mt-he-en")
19
+
20
+
21
+ # Define the function
22
+ def predict(text):
23
+ # Return the translation
24
+ return pipe(text)[0]["translation_text"]
25
+
26
+ def predict_reverse(text):
27
+ # Return the translation
28
+ return pipe_reverse(text)[0]["translation_text"]
29
+
30
+ # Define the interface
31
+ iface = gr.Interface(
32
+ fn=predict,
33
+ fn_reverse=predict_reverse,
34
+ inputs='text',
35
+ outputs='text',
36
+ title="English to Hebrew Translator",
37
+ description="Translate English to Hebrew",
38
+ examples=[["Hello! My name is Bob."], ["I like to eat apples and banana"]]
39
+ )
40
+
41
+
42
+
43
+ # Launch the interface
44
+ iface.launch()
45