Spaces:
Sleeping
Sleeping
File size: 942 Bytes
6c4a93d 5340d4e f5cb146 5340d4e daea5cb 4779f2c 5340d4e 6c4a93d cae0258 07b3a85 6a6af53 cae0258 07b3a85 ea44c7c 6e7e6a9 b7f1129 5340d4e b7f1129 |
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 |
import gradio as gr
from transformers import pipeline
# Load the GPT-2 model from Hugging Face using the pipeline
generator = pipeline('text-generation', model='gpt2-medium')
def generate_text(prompt, max_length=50):
# Generate text using the GPT-2 model
generated_text = generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text']
return generated_text
# Create a Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.Textbox(lines=3, placeholder="Enter your prompt here...", label="Prompt"),
gr.Slider(minimum=10, maximum=250, value=100, label="Max Length"),
],
outputs=gr.Textbox(label="Generated Text"),
title="GPT-2 Text Generator (OUTDATED)",
description="Enter a prompt and generate text using GPT-2 on Hugging Face. Try out other models [here](https://huggingface.co/tchans123)."
)
# Launch the Gradio interface
iface.launch(share=True)
|