File size: 750 Bytes
72230ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()