File size: 836 Bytes
890f040 c6f5946 890f040 657dbb4 890f040 9f2d4e6 c6f5946 890f040 26b0847 890f040 c6f5946 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_translation")
model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_translation")
def translate(text):
input_ids = tokenizer(text, return_tensors="pt", truncation=True)['input_ids']
output_ids = model.generate(input_ids)
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
return output_text
iface_translate = gr.Interface(
fn=translate,
inputs=gr.inputs.Textbox(lines=10, label="Input Text"),
outputs=gr.outputs.Textbox(label="Translation"),
title="ScienceBrief Translation",
description="Translate any Spanish text to English using our ScienceBrief model",
theme="compact"
)
iface_translate.launch()
|