Text_Generation / app.py
Shangkhonil's picture
Create app.py
72230ff verified
raw
history blame contribute delete
750 Bytes
import gradio as gr
from transformers import pipeline
# Load the text generation pipeline with the GPT-2 model
pipe = pipeline("text-generation", model="openai-community/gpt2")
def generate_text(prompt):
# Generate text using the pipeline
result = pipe(prompt, max_length=100, num_return_sequences=1)
return result[0]['generated_text']
# Create Gradio interface
title = "GPT-2 Text Generation"
description = "Generate text based on a prompt using the GPT-2 model."
interface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(label="Enter your prompt"),
outputs=gr.Textbox(label="Generated Text"),
title=title,
description=description,
)
# Launch the Gradio app
if __name__ == "__main__":
interface.launch()