Spaces:
Sleeping
Sleeping
File size: 3,179 Bytes
e87b210 d3ee320 b507f98 e87b210 0bb036a 15c2e5c b507f98 0f9899f b507f98 f320f41 b507f98 d3ee320 b507f98 d3ee320 0f9899f 4dcbdb7 b507f98 0f9899f d3ee320 0f9899f b507f98 d3ee320 b507f98 d3ee320 b507f98 7a4282d 008cf16 7a4282d f320f41 d3ee320 4dcbdb7 3746217 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
import torch
model = AutoModelForSeq2SeqLM.from_pretrained("Mamadou2727/Feriji_model")
tokenizer = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
device = "cuda:0" if torch.cuda.is_available() else "cpu"
LANG_CODES = {
"French": "fr",
"Zarma": "yo"
}
def translate(text, candidates: int):
"""
Translate the text from French to Zarma
"""
src = LANG_CODES["French"]
tgt = LANG_CODES["Zarma"]
tokenizer.src_lang = src
tokenizer.tgt_lang = tgt
ins = tokenizer(text, return_tensors='pt').to(device)
gen_args = {
'return_dict_in_generate': True,
'output_scores': True,
'output_hidden_states': True,
'length_penalty': 0.0, # don't encourage longer or shorter output,
'num_return_sequences': candidates,
'num_beams': candidates,
'forced_bos_token_id': tokenizer.lang_code_to_id[tgt]
}
outs = model.generate(**{**ins, **gen_args})
output = tokenizer.batch_decode(outs.sequences, skip_special_tokens=True)
return '\n'.join(output)
with gr.Blocks() as app:
markdown = r"""
# Feriji-fr-to-dje v.1.1, Proudly made by Elysabhete, Habibatou & Mamadou K.
<img src="https://cdn-uploads.huggingface.co/production/uploads/63cc1d4bf488db9bb3c6449e/AtOKLAaL5kt0VhRsxE0vf.png" width="500" height="300">
Feriji-fr-to-dje is a beta version of the French to Zarma translator.
## Intended Uses & Limitations
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.
## Authors:
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.
## Citations
If you use this dataset or model in your research, please cite it as follows:
@dataset{Feriji,
author = {Habibatou Abdoulaye Alfari, Elysabhete Ibrahim Amadou and Mamadou K. KEITA},
title = {Feriji, a French-Zarma Parallel Corpus},
year = 2023,
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/27-GROUP/Feriji}}
}
"""
with gr.Row():
gr.Markdown(markdown)
with gr.Column():
input_text = gr.components.Textbox(lines=7, label="Input Text", value="")
return_seqs = gr.Slider(label="Number of return sequences", value=1, minimum=1, maximum=12, step=1)
outputs = gr.Textbox(lines=7, label="Output Text")
translate_btn = gr.Button("Traduis!")
translate_btn.click(translate, inputs=[input_text, return_seqs], outputs=outputs)
app.launch(share=True) |