File size: 707 Bytes
71ad94c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import gradio as gr
from transformers import SeamlessM4TForTextToText
from transformers import AutoProcessor, SeamlessM4TModel
model = SeamlessM4TForTextToText.from_pretrained("facebook/hf-seamless-m4t-medium")
processor = AutoProcessor.from_pretrained("facebook/hf-seamless-m4t-medium")

text_inputs = processor(text = "Hello, my dog is cute", src_lang="eng", return_tensors="pt")
output_tokens = model.generate(**text_inputs, tgt_lang="pan")
translated_text_from_text = processor.decode(output_tokens[0].tolist(), skip_special_tokens=True)
print(translated_text_from_text)

def greet(name):
    return translated_text_from_text

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()