Spaces:
Runtime error
Runtime error
File size: 715 Bytes
2fd5b9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from transformers import pipeline
import gradio as gr
PIPELINES = {}
def build_pipeline(size):
global PIPELINES
if size in PIPELINES:
return PIPELINES[size]
PIPELINES[size] = pipeline(
"text2text-generation", model=f"google/flan-t5-{size}", max_length=256
)
return PIPELINES[size]
def greet(input_text, size):
pipe = build_pipeline(size)
return pipe(input_text)[0]["generated_text"]
demo = gr.Interface(
fn=greet,
inputs=[
gr.Textbox(lines=2, placeholder="Enter your task text..."),
gr.Radio(choices=["small", "base", "large", "xl"], value="base"),
],
outputs=[gr.Textbox(lines=2)],
)
if __name__ == "__main__":
demo.launch()
|