coroianpetruta commited on
Commit
821b37c
1 Parent(s): 2f5766d

Modified app

Browse files
Files changed (1) hide show
  1. app.py +38 -4
app.py CHANGED
@@ -1,7 +1,41 @@
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: enro-app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['model_name', 'tokenizer', 'model', 'text', 'translationsout_1', 'translationsout_2', 'translationsout_3',
5
+ 'translationsout_4', 'examples', 'intf', 'get_translations']
6
+
7
+ # %% enro-app.ipynb 1
8
+ from transformers import MarianMTModel, MarianTokenizer
9
  import gradio as gr
10
 
11
+ # %% enro-app.ipynb 2
12
+ model_name = "Helsinki-NLP/opus-mt-tc-big-en-ro"
13
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
14
+ model = MarianMTModel.from_pretrained(model_name)
15
+
16
+ # %% enro-app.ipynb 3
17
+ def get_translations(input_text):
18
+ tokenized_text = tokenizer(input_text, return_tensors="pt")
19
+
20
+ # Generate multiple translations
21
+ # Set num_return_sequences to the number of translations you want
22
+ translated = model.generate(**tokenized_text, num_return_sequences=4)
23
+ translations = []
24
+ for t in translated:
25
+ translations.append(tokenizer.decode(t, skip_special_tokens=True))
26
+
27
+ return translations[0], translations[1], translations[2], translations[3]
28
+
29
+ # %% enro-app.ipynb 5
30
+ text = gr.components.Text()
31
+ translationsout_1 = gr.components.Text(label="Translation 1.")
32
+ translationsout_2 = gr.components.Text(label="Translation 2")
33
+ translationsout_3 = gr.components.Text(label="Translation 3")
34
+ translationsout_4 = gr.components.Text(label="Translation 4")
35
+ examples = ['The small mouse jumped.',"He's a bad writer.",'What is the way to the park?']
36
+ intf = gr.Interface(fn=get_translations, inputs=text,outputs=[translationsout_1, translationsout_2, translationsout_3, translationsout_4],examples=examples)
37
+
38
+
39
+
40
+ intf.launch()
41