Spaces:
Running
Running
| 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() | |