RishabhBhardwaj's picture
Try
0f38c2e
import gradio as gr
from transformers import pipeline
# Load a pre-trained text generation model from Hugging Face
generator = pipeline('text-generation', model='gpt2')
def generate_text(prompt):
# Generate text using the model
result = generator(prompt, max_length=100, num_return_sequences=1)
return result[0]['generated_text']
# Create a Gradio interface
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator", description="Enter a prompt to generate text.")
# Launch the interface
if __name__ == "__main__":
interface.launch()