File size: 555 Bytes
1af5791
dbc8937
 
 
 
 
 
 
 
 
 
 
 
 
1af5791
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")

input_text = "translate English to German: How old are you?"


def greet(input_text):
    input_ids = tokenizer(input_text, return_tensors="pt").input_ids

    outputs = model.generate(input_ids, max_length=40)
    return tokenizer.decode(outputs[0])


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