Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +14 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSeq2SeqLM,AutoTokenizer
|
2 |
+
import gradio as grad
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
model_c = 'Ahmed107/nllb200-ar-en'
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_c,src_lang='ajp_Arab', tgt_lang='eng_Latn')
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_c)
|
7 |
+
|
8 |
+
def translate(text):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt")
|
10 |
+
outputs = model.generate(**inputs, max_length=128, num_beams=5, early_stopping=True)
|
11 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
return response
|
14 |
+
grad.Interface(translate, inputs=["text",], outputs="text").launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
transformers[sentencepiece]
|