profplate commited on
Commit
effb5d0
·
verified ·
1 Parent(s): 294da11

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load distilgpt2 — a small text generation model (82M parameters)
5
+ print("Loading text generation model (distilgpt2)...")
6
+ generator = pipeline(
7
+ "text-generation",
8
+ model="distilbert/distilgpt2",
9
+ )
10
+ print("Model loaded!")
11
+
12
+
13
+ def generate_text(prompt):
14
+ """Generate a continuation of the input text."""
15
+ if not prompt or not prompt.strip():
16
+ return "Type a sentence or two and watch the model try to continue it."
17
+
18
+ # Generate with default settings — no temperature control yet
19
+ # (that's Session 5!)
20
+ result = generator(
21
+ prompt,
22
+ max_new_tokens=80,
23
+ num_return_sequences=1,
24
+ do_sample=True,
25
+ truncation=True,
26
+ )
27
+
28
+ return result[0]["generated_text"]
29
+
30
+
31
+ demo = gr.Interface(
32
+ fn=generate_text,
33
+ inputs=gr.Textbox(
34
+ lines=4,
35
+ placeholder="Type a sentence or the beginning of a story...",
36
+ label="Your Prompt",
37
+ ),
38
+ outputs=gr.Textbox(
39
+ label="What the Model Wrote",
40
+ lines=8,
41
+ ),
42
+ title="Text Generator",
43
+ description=(
44
+ "This model doesn't classify — it creates. "
45
+ "Type a sentence and watch it try to write what comes next. "
46
+ "It's a small model (82M parameters), so the results won't be "
47
+ "perfect — but it's doing something fundamentally different from "
48
+ "the classification models we've used so far."
49
+ ),
50
+ examples=[
51
+ ["Monday morning arrived like a gift from the universe — truly, what better way to start the week than"],
52
+ ["The acceptance letter sat on the kitchen table, and she couldn't stop reading it."],
53
+ ["The volcano had been dormant for three hundred years. When it finally erupted,"],
54
+ ["Once upon a time, in a city made entirely of glass,"],
55
+ ["The capital of France is"],
56
+ ],
57
+ )
58
+
59
+ demo.launch()