File size: 870 Bytes
90156bb f69b2fe 9720200 f69b2fe 90156bb 9720200 df9f949 9720200 f69b2fe 56da838 f69b2fe 9720200 90156bb 9720200 90156bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import gradio as gr
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
model = MBartForConditionalGeneration.from_pretrained("SnypzZz/Llama2-13b-Language-translate")
tokenizer = MBart50TokenizerFast.from_pretrained("SnypzZz/Llama2-13b-Language-translate", src_lang="en_XX")
dropdown = gr.Dropdown(["de_DE", "es_XX", "fr_XX", "sv_SE", "ru_RU"], label="Choose Output Language")
def execute(input, dropdown_value):
model_inputs = tokenizer(input, return_tensors="pt")
generated_tokens = model.generate(
**model_inputs,
forced_bos_token_id=tokenizer.lang_code_to_id[dropdown_value]
)
output = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
output = output.strip("[]' ")
return output
iface = gr.Interface(fn=execute, inputs=["textbox", dropdown], outputs="textbox")
iface.launch() |