Spaces:
Runtime error
Runtime error
MohamedUgas
commited on
Commit
•
cad4b8f
1
Parent(s):
98f8824
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
import torch
|
4 |
+
from ui import title, description, examples
|
5 |
+
from langs import LANGS
|
6 |
+
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
9 |
+
|
10 |
+
device = 0 if torch.cuda.is_available() else -1
|
11 |
+
|
12 |
+
src_lang = 'som_Latn'
|
13 |
+
tgt_lang = "eng_Latn"
|
14 |
+
|
15 |
+
def translate(text):
|
16 |
+
translation_pipeline = pipeline("translation",
|
17 |
+
model=model,
|
18 |
+
tokenizer=tokenizer,
|
19 |
+
src_lang=src_lang,
|
20 |
+
tgt_lang=tgt_lang,
|
21 |
+
device=device)
|
22 |
+
|
23 |
+
result = translation_pipeline(text)
|
24 |
+
return result[0]['translation_text']
|
25 |
+
|
26 |
+
|
27 |
+
gr.Interface(
|
28 |
+
translate,
|
29 |
+
[
|
30 |
+
gr.components.Textbox(label="Text")
|
31 |
+
],
|
32 |
+
["text"],
|
33 |
+
).launch()
|