Mamadou2727 commited on
Commit
d3ee320
·
1 Parent(s): 1dc68ce
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -1,10 +1,7 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  import torch
4
- import base64
5
- import io
6
 
7
- # Load the model and tokenizer
8
  model = AutoModelForSeq2SeqLM.from_pretrained("Mamadou2727/Feriji_model")
9
  tokenizer = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
10
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
@@ -15,8 +12,9 @@ LANG_CODES = {
15
 
16
  def translate(text, candidates: int):
17
  """
18
- Translate the text from French to Zarma.
19
  """
 
20
  src = LANG_CODES["French"]
21
  tgt = LANG_CODES["Zarma"]
22
 
@@ -29,7 +27,7 @@ def translate(text, candidates: int):
29
  'return_dict_in_generate': True,
30
  'output_scores': True,
31
  'output_hidden_states': True,
32
- 'length_penalty': 0.0,
33
  'num_return_sequences': candidates,
34
  'num_beams': candidates,
35
  'forced_bos_token_id': tokenizer.lang_code_to_id[tgt]
@@ -40,29 +38,43 @@ def translate(text, candidates: int):
40
 
41
  return '\n'.join(output)
42
 
43
- def translate_file(uploaded_file, candidates: int):
44
- if uploaded_file is None:
45
- return "No file uploaded."
46
-
47
- # Decode the file content
48
- file_content = base64.b64decode(uploaded_file['data'].split(',')[1])
49
- text = io.BytesIO(file_content).read().decode("utf-8").strip()
50
-
51
- return translate(text, candidates)
52
-
53
-
54
  with gr.Blocks() as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  with gr.Row():
56
- gr.Markdown("Your markdown content here")
57
  with gr.Column():
58
  input_text = gr.components.Textbox(lines=7, label="Input Text", value="")
59
  return_seqs = gr.Slider(label="Number of return sequences", value=1, minimum=1, maximum=12, step=1)
60
  outputs = gr.Textbox(lines=7, label="Output Text")
61
- translate_btn = gr.Button("Translate Text")
62
- translate_btn.click(translate, inputs=[input_text, return_seqs], outputs=outputs)
63
 
64
- upload_file = gr.File(label="Upload File")
65
- translate_file_btn = gr.Button("Translate Uploaded File")
66
- translate_file_btn.click(translate_file, inputs=[upload_file, return_seqs], outputs=outputs)
67
 
68
  app.launch(share=True)
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
  import torch
 
 
4
 
 
5
  model = AutoModelForSeq2SeqLM.from_pretrained("Mamadou2727/Feriji_model")
6
  tokenizer = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
7
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
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
 
 
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]
 
38
 
39
  return '\n'.join(output)
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="500" height="300">
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(lines=7, 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(lines=7, 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)