jjuarez commited on
Commit
890f040
1 Parent(s): 4f016ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
+
4
+ # Loading translation model
5
+ translation_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_translation")
6
+ translation_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_translation")
7
+
8
+
9
+ def translate(text):
10
+ input_ids = translation_tokenizer.encode(text, return_tensors="pt")
11
+ output_ids = translation_model.generate(input_ids)
12
+ output_text = translation_tokenizer.decode(output_ids[0], skip_special_tokens=True)
13
+ return output_text
14
+
15
+ iface_translate = gr.Interface(
16
+ fn=translate,
17
+ inputs=gr.inputs.Textbox(lines=10, label="Input Text"),
18
+ outputs=gr.outputs.Textbox(label="Translation"),
19
+ title="ScienceBrief Translation",
20
+ description="Translate your text into French using the ScienceBrief translation model.",
21
+ theme="compact"
22
+ )
23
+
24
+ iface_translate.launch()