Spaces:
Sleeping
Sleeping
File size: 594 Bytes
b8c9763 b53b4a9 b8c9763 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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()
|