File size: 679 Bytes
80a9adc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import gradio as gr
from transformers import pipeline
# Create a text-generation pipeline using GPT-2
generator = pipeline('text-generation', model='gpt2')
def generate_text(prompt):
# Generate text with a maximum length of 50 tokens
generated = generator(prompt, max_length=50, num_return_sequences=1)
return generated[0]['generated_text']
# Create a Gradio interface with one text input and one text output
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Simple LLM with Hugging Face & Gradio",
description="Enter a prompt and get text generated by a basic GPT-2 model."
)
# Launch the interface
iface.launch()
|