Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load pre-trained text generation pipeline | |
generator = pipeline("text-generation", model="gpt2") | |
# Define the function to generate text | |
def generate_text(prompt): | |
generated = generator(prompt, max_length=50, num_return_sequences=1) | |
return generated[0]['generated_text'] | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=generate_text, | |
inputs="text", | |
outputs="text", | |
title="Text Generation", | |
description="Generate text using GPT-2" | |
) | |
# Launch the interface | |
if __name__ == "__main__": | |
iface.launch() | |