Mamadou2727 commited on
Commit
6f6dfd6
·
1 Parent(s): 4fab891

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -54
app.py CHANGED
@@ -2,21 +2,21 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
  import torch
4
 
5
- model = AutoModelForSeq2SeqLM.from_pretrained("Mamadou2727/Feriji_Translator_v1.1")
6
  tokenizer = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
7
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
8
  LANG_CODES = {
9
- "French":"fr",
10
- "Zarma":"yo"
11
  }
12
 
13
- def translate(text, src_lang, tgt_lang, candidates:int):
14
  """
15
- Translate the text from source lang to target lang
16
  """
17
 
18
- src = LANG_CODES.get(src_lang)
19
- tgt = LANG_CODES.get(tgt_lang)
20
 
21
  tokenizer.src_lang = src
22
  tokenizer.tgt_lang = tgt
@@ -24,15 +24,14 @@ def translate(text, src_lang, tgt_lang, candidates:int):
24
  ins = tokenizer(text, return_tensors='pt').to(device)
25
 
26
  gen_args = {
27
- 'return_dict_in_generate': True,
28
- 'output_scores': True,
29
- 'output_hidden_states': True,
30
- 'length_penalty': 0.0, # don't encourage longer or shorter output,
31
- 'num_return_sequences': candidates,
32
- 'num_beams':candidates,
33
- 'forced_bos_token_id': tokenizer.lang_code_to_id[tgt]
34
- }
35
-
36
 
37
  outs = model.generate(**{**ins, **gen_args})
38
  output = tokenizer.batch_decode(outs.sequences, skip_special_tokens=True)
@@ -41,54 +40,41 @@ def translate(text, src_lang, tgt_lang, candidates:int):
41
 
42
  with gr.Blocks() as app:
43
  markdown = r"""
44
- # Feriji-fr-to-dje v.1.1, Proudly made by Elysabhete, Habibatou & Mamadou K.
45
-
46
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/63cc1d4bf488db9bb3c6449e/AtOKLAaL5kt0VhRsxE0vf.png)
47
-
48
- Feriji-fr-to-dje is a beta version of the French to Zarma translator.
49
-
50
- ## Intended Uses & Limitations
51
-
52
- This model is intended for academic research and practical applications in machine translation. It can be used to translate French text to Zarma and vice versa. Users should note that the model's performance may vary based on the complexity and context of the input text.
53
-
54
- ## Authors:
55
- The project, **Feriji dataset and Feriji-fr-to-dje**, was curated by **Elysabhete Ibrahim Amadou** and **Mamadou K. KEITA**, with the aim to enhance linguistic studies and translation capabilities between French and Zarma.
56
 
57
- ## Citations
58
 
59
- If you use this dataset or model in your research, please cite it as follows:
 
 
60
 
61
- @dataset{Feriji,
62
- author = {Habibatou Abdoulaye Alfari, Elysabhete Ibrahim Amadou and Mamadou K. KEITA},
63
- title = {Feriji, a French-Zarma Parallel Corpus},
64
- year = 2023,
65
- publisher = {GitHub},
66
- journal = {GitHub repository},
67
- howpublished = {\url{https://github.com/27-GROUP/Feriji}}
68
- }
 
 
 
 
 
 
 
 
 
69
  """
70
 
71
-
72
  with gr.Row():
73
  gr.Markdown(markdown)
74
  with gr.Column():
75
  input_text = gr.components.Textbox(label="Input Text", value="")
76
  return_seqs = gr.Slider(label="Number of return sequences", value=1, minimum=1, maximum=12, step=1)
77
- source_lang = gr.components.Dropdown(label="Source Language", value="French", choices=list(LANG_CODES.keys()))
78
- target_lang = gr.components.Dropdown(label="Target Language", value="Zarma", choices=list(LANG_CODES.keys()))
79
- inputs=[input_text, source_lang, target_lang, return_seqs]
80
- outputs = gr.Textbox()
81
 
82
  translate_btn = gr.Button("Traduis!")
83
- translate_btn.click(translate, inputs=inputs, outputs=outputs)
84
- """"
85
- gr.Examples(
86
- [
87
- ["Hello! How are you?", "English", "toki pona", 3],
88
- ["toki a! ilo pi ante toki ni li pona!", "toki pona", "English", 3],
89
- ["mi li toki e toki pona", "toki pona", "toki pona", 3],
90
- ],
91
- inputs=inputs
92
- )
93
- """
94
  app.launch(share=True)
 
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
  import torch
4
 
5
+ model = AutoModelForSeq2SeqLM.from_pretrained("Mamadou2727/m2m100_418M-fr")
6
  tokenizer = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
7
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
8
  LANG_CODES = {
9
+ "French": "fr",
10
+ "Zarma": "yo"
11
  }
12
 
13
+ def translate(text, candidates: int):
14
  """
15
+ Translate the text from French to Zarma
16
  """
17
 
18
+ src = LANG_CODES["French"]
19
+ tgt = LANG_CODES["Zarma"]
20
 
21
  tokenizer.src_lang = src
22
  tokenizer.tgt_lang = tgt
 
24
  ins = tokenizer(text, return_tensors='pt').to(device)
25
 
26
  gen_args = {
27
+ 'return_dict_in_generate': True,
28
+ 'output_scores': True,
29
+ 'output_hidden_states': True,
30
+ 'length_penalty': 0.0, # don't encourage longer or shorter output,
31
+ 'num_return_sequences': candidates,
32
+ 'num_beams': candidates,
33
+ 'forced_bos_token_id': tokenizer.lang_code_to_id[tgt]
34
+ }
 
35
 
36
  outs = model.generate(**{**ins, **gen_args})
37
  output = tokenizer.batch_decode(outs.sequences, skip_special_tokens=True)
 
40
 
41
  with gr.Blocks() as app:
42
  markdown = r"""
43
+ # Feriji-fr-to-dje v.1.1, Proudly made by Elysabhete, Habibatou & Mamadou K.
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/63cc1d4bf488db9bb3c6449e/AtOKLAaL5kt0VhRsxE0vf.png" width="300" height="250">
46
 
47
+ Feriji-fr-to-dje is a beta version of the French to Zarma translator.
48
+
49
+ ## Intended Uses & Limitations
50
 
51
+ This model is intended for academic research and practical applications in machine translation. It can be used to translate French text to Zarma and vice versa. Users should note that the model's performance may vary based on the complexity and context of the input text.
52
+
53
+ ## Authors:
54
+ The project, **Feriji dataset and Feriji-fr-to-dje**, was curated by **Elysabhete Ibrahim Amadou** and **Mamadou K. KEITA**, with the aim to enhance linguistic studies and translation capabilities between French and Zarma.
55
+
56
+ ## Citations
57
+
58
+ If you use this dataset or model in your research, please cite it as follows:
59
+
60
+ @dataset{Feriji,
61
+ author = {Habibatou Abdoulaye Alfari, Elysabhete Ibrahim Amadou and Mamadou K. KEITA},
62
+ title = {Feriji, a French-Zarma Parallel Corpus},
63
+ year = 2023,
64
+ publisher = {GitHub},
65
+ journal = {GitHub repository},
66
+ howpublished = {\url{https://github.com/27-GROUP/Feriji}}
67
+ }
68
  """
69
 
 
70
  with gr.Row():
71
  gr.Markdown(markdown)
72
  with gr.Column():
73
  input_text = gr.components.Textbox(label="Input Text", value="")
74
  return_seqs = gr.Slider(label="Number of return sequences", value=1, minimum=1, maximum=12, step=1)
75
+ outputs = gr.Textbox(label="Output Text")
 
 
 
76
 
77
  translate_btn = gr.Button("Traduis!")
78
+ translate_btn.click(translate, inputs=[input_text, return_seqs], outputs=outputs)
79
+
 
 
 
 
 
 
 
 
 
80
  app.launch(share=True)