Spaces:
Sleeping
Sleeping
File size: 1,189 Bytes
e6ab0e9 219a769 e6ab0e9 |
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 35 36 37 38 |
import gradio as gr
from transformers import pipeline
# Load the pipeline for text2text-generation using the Blenderbot model
pipe = pipeline(task="text2text-generation", model="facebook/blenderbot-400M-distill")
# Define the text generation function
def generate_text(prompt, max_length=50):
response = pipe(prompt, max_length=max_length, truncation=True)
return response[0]['generated_text']
# Create the Gradio app interface
with gr.Blocks() as app:
gr.Markdown("## Text-to-Text Generation App")
gr.Markdown(
"Enter a prompt below and the model will generate text. "
"This app uses the `facebook/blenderbot-400M-distill` model."
)
with gr.Row():
input_prompt = gr.Textbox(label="Input Prompt", placeholder="Type your prompt here...")
output_text = gr.Textbox(label="Generated Text")
max_length = gr.Slider(label="Max Length", minimum=10, maximum=200, step=10, value=50)
submit_button = gr.Button("Generate")
submit_button.click(
fn=generate_text,
inputs=[input_prompt, max_length],
outputs=output_text
)
# Launch the app
if __name__ == "__main__":
app.launch()
|