File size: 762 Bytes
aad68e2 8a4bc31 aad68e2 8a4bc31 aad68e2 8a4bc31 7c64be6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import gradio as gr
from transformers import pipeline
# Load the text generation pipeline from Hugging Face
generator = pipeline("text-generation", model="gpt-2")
def generate_text(prompt):
# Generate text based on the input prompt
results = generator(prompt, max_length=100, num_return_sequences=1)
return results[0]['generated_text']
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=gr.inputs.Textbox(label="Input Prompt", lines=2, placeholder="Enter your prompt here..."),
outputs=gr.outputs.Textbox(label="Generated Text"),
title="Text Generation with GPT-2",
description="Enter a prompt and get a generated text using the GPT-2 model from Hugging Face."
)
# Launch the interface
iface.launch() |