|
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"], label="Choose Output Language") |
|
|
|
def d(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_DE = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0] |
|
output_DE = output_DE.strip("[]' ") |
|
return output_DE |
|
|
|
iface = gr.Interface(fn=d, inputs=["textbox", dropdown], outputs="textbox") |
|
iface.launch() |