File size: 747 Bytes
403d059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# 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()