Iosif24 commited on
Commit
6ceb35a
·
1 Parent(s): a56e35d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -3
app.py CHANGED
@@ -1,11 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
  import gradio as grad
 
3
  model_name = "Helsinki-NLP/opus-mt-en-de"
4
  opus_translator = pipeline("translation", model=model_name)
5
 
6
  def translate(text):
7
  response = opus_translator(text)
8
- return response
9
- grad.Interface(translate, inputs=["text",], outputs="text").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- #Please make sure you have `sentencepiece` installed in order to use this tokenizer.
 
1
+ # from transformers import pipeline
2
+ # import gradio as grad
3
+ # model_name = "Helsinki-NLP/opus-mt-en-de"
4
+ # opus_translator = pipeline("translation", model=model_name)
5
+
6
+ # def translate(text):
7
+ # response = opus_translator(text)
8
+ # return response
9
+ # grad.Interface(translate, inputs=["text",], outputs="text").launch()
10
+
11
+ #Please make sure you have `sentencepiece` installed in order to use this tokenizer.
12
+
13
  from transformers import pipeline
14
  import gradio as grad
15
+
16
  model_name = "Helsinki-NLP/opus-mt-en-de"
17
  opus_translator = pipeline("translation", model=model_name)
18
 
19
  def translate(text):
20
  response = opus_translator(text)
21
+ return response[0]['translation_text']
22
+
23
+ iface = grad.Interface(
24
+ fn=translate,
25
+ inputs=[
26
+ grad.Textbox(
27
+ placeholder="Enter the text in English...",
28
+ label="English Text",
29
+ lines=5
30
+ )
31
+ ],
32
+ outputs=grad.Textbox(label="German Translation"),
33
+ live=True,
34
+ title="English to German Translator",
35
+ description="Type in English and get the translation in German instantly!",
36
+ examples=[
37
+ ["Hello, how are you?"],
38
+ ["The weather is nice today."],
39
+ ["Gradio is great for creating interfaces."]
40
+ ],
41
+ theme="dark", # Use a dark theme for the interface
42
+ layout="horizontal", # Use a horizontal layout
43
+ allow_flagging="never", # Disable the flagging option
44
+ css="""
45
+ .interface { max-width: 800px; margin: auto; }
46
+ .input_textbox { font-size: 16px; }
47
+ .output_textbox { font-size: 16px; }
48
+ """
49
+ )
50
 
51
+ iface.launch()