|
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() |
|
|