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