import gradio as gr from transformers import pipeline # Load the text generation model generator = pipeline("text-generation", model="gpt2", max_length=100) def generate_description(topic): # Prompt the model to describe the topic prompt = f"Describe the following topic briefly: {topic}" result = generator(prompt, max_length=100, num_return_sequences=1) return result[0]["generated_text"] # Create Gradio interface interface = gr.Interface( fn=generate_description, inputs=gr.Textbox(label="Enter a Topic", placeholder="e.g., Heart"), outputs=gr.Textbox(label="Description"), title="Topic Describer", description="Enter a topic, and the app will describe it briefly." ) # Launch the app interface.launch()