Spaces:
Runtime error
Runtime error
Commit
·
6aff4c0
1
Parent(s):
f99175d
Create mt0_translate_eng_darija
Browse files- mt0_translate_eng_darija +41 -0
mt0_translate_eng_darija
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import time
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 6 |
+
|
| 7 |
+
def translation(text):
|
| 8 |
+
|
| 9 |
+
model_checkpoint = "bigscience/mt0-base"
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
| 11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint).to('cuda')
|
| 12 |
+
#inference
|
| 13 |
+
inputs = tokenizer("translate to arabic : hi, I am salma and you?", return_tensors="pt").to("cuda")
|
| 14 |
+
output = model.generate(**inputs)
|
| 15 |
+
output = tokenizer.decode(output.cpu().numpy()[0])
|
| 16 |
+
|
| 17 |
+
return output
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if __name__ == '__main__':
|
| 21 |
+
print('\tinit models')
|
| 22 |
+
|
| 23 |
+
#inputs = [gr.inputs.Radio(['nllb-distilled-600M', 'nllb-1.3B', 'nllb-distilled-1.3B'], label='NLLB Model'),
|
| 24 |
+
inputs = [gr.inputs.Textbox(lines=5, label="Input text")]
|
| 25 |
+
|
| 26 |
+
outputs = gr.outputs.Textbox(label="Input text")
|
| 27 |
+
|
| 28 |
+
title = "NLP Translation model from english to darija"
|
| 29 |
+
|
| 30 |
+
demo_status = "Demo is running on CPU"
|
| 31 |
+
description = f"Details: https://github.com/facebookresearch/fairseq/tree/nllb. {demo_status}"
|
| 32 |
+
examples = [
|
| 33 |
+
['English', 'Darija', 'Hi nice to meet you']
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
gr.Interface(translation,
|
| 37 |
+
inputs,
|
| 38 |
+
outputs,
|
| 39 |
+
title=title,
|
| 40 |
+
description=description,
|
| 41 |
+
).launch(debug=True)
|