File size: 1,951 Bytes
37e6996
 
 
 
 
7b4255f
37e6996
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b4255f
 
 
 
 
37e6996
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
from transformers import pipeline

generator = pipeline("text-generation", model="distilbert/distilgpt2", device=-1)

def generate_text(prompt, temperature, max_tokens):
    if not prompt.strip():
        return "Please enter a prompt."
    result = generator(
        prompt,
        max_new_tokens=int(max_tokens),
        temperature=float(temperature),
        do_sample=True,
        truncation=True,
    )
    return result[0]["generated_text"]

demo = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.Textbox(
            label="Prompt",
            placeholder="Start typing about birds...",
            lines=3,
            value="The northern cardinal sings",
        ),
        gr.Slider(
            minimum=0.1,
            maximum=2.0,
            value=1.0,
            step=0.1,
            label="Temperature",
            info="Lower = more predictable, Higher = more creative",
        ),
        gr.Slider(
            minimum=20,
            maximum=200,
            value=80,
            step=10,
            label="Max New Tokens",
            info="How much text to generate",
        ),
    ],
    outputs=gr.Textbox(label="Generated Text", lines=8),
    title="Bird Text Generator",
    description=(
        "A text generation playground using distilgpt2, customized with bird-themed prompts. "
        "This is Riley's Space 1 — a baseline text generator. It can write about birds "
        "but doesn't actually know anything about them. Try different temperature settings "
        "to see how randomness affects the output."
    ),
    examples=[
        ["The northern cardinal sings", 1.0, 80],
        ["In the forest canopy, the warbler", 0.7, 100],
        ["Migration patterns suggest that", 0.5, 120],
        ["The red-tailed hawk circled above the parking lot", 1.0, 80],
        ["At dawn, the chorus of birdsong", 1.3, 100],
    ],
    theme=gr.themes.Soft(),
)

demo.launch()