import gradio as gr from transformers import pipeline # Load the GPT-2 model generator = pipeline('text-generation', model='gpt2') 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'] # Set up the Gradio interface interface = gr.Interface( fn=generate_text, inputs=gr.inputs.Textbox(lines=2, placeholder="Type something here..."), outputs='text', title="Simple Generative AI", description="Type in a prompt and get a continuation from GPT-2!" ) if __name__ == "__main__": interface.launch()