NadiaHassan commited on
Commit
f7cd6c5
1 Parent(s): a568d61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSeq2SeqLM,AutoTokenizer
2
+ import gradio as grad
3
+ mdl_name = "Helsinki-NLP/opus-mt-ar-en"
4
+ mdl = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
5
+ my_tkn = AutoTokenizer.from_pretrained(mdl_name)
6
+
7
+ #opus_translator = pipeline("translation", model=mdl_name)
8
+
9
+ def translate(text):
10
+ inputs = my_tkn(text, return_tensors="pt")
11
+ trans_output = mdl.generate(**inputs)
12
+ response = my_tkn.decode(trans_output[0], skip_special_tokens=True)
13
+
14
+ #response = opus_translator(text)
15
+ return response
16
+ grad.Interface(translate, inputs=["text",], outputs="text").launch()