CryptoCreeper commited on
Commit
835d2fc
·
verified ·
1 Parent(s): 7a8ae95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -37
app.py CHANGED
@@ -6,11 +6,6 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
6
  from diffusers import DiffusionPipeline, LCMScheduler
7
  from PIL import Image, ImageFilter
8
 
9
- # ===============================
10
- # PASSWORD
11
- # ===============================
12
- PASSWORD = "CREEPERIMG"
13
-
14
  # ===============================
15
  # TEXT MODEL (PROMPT ENHANCER)
16
  # ===============================
@@ -20,10 +15,6 @@ tokenizer = AutoTokenizer.from_pretrained(TEXT_MODEL_ID)
20
  text_model = AutoModelForCausalLM.from_pretrained(TEXT_MODEL_ID)
21
 
22
  def enhance_prompt(user_prompt: str) -> str:
23
- """
24
- Enhances the user prompt for image generation.
25
- Returns ONLY the enhanced prompt text.
26
- """
27
  instruction = (
28
  "Please enhance this prompt so it is suitable for an image generator "
29
  "that requires clear instructions. Analyse the prompt, and output as "
@@ -42,7 +33,6 @@ def enhance_prompt(user_prompt: str) -> str:
42
 
43
  decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
44
 
45
- # ⛔️ CRITICAL: extract only what comes AFTER "Enhanced prompt:"
46
  if "Enhanced prompt:" in decoded:
47
  decoded = decoded.split("Enhanced prompt:")[-1]
48
 
@@ -81,31 +71,20 @@ def estimate_time(steps, res):
81
  # ===============================
82
  # GENERATION FUNCTION
83
  # ===============================
84
- def generate(password, prompt, negative, resolution, steps):
85
  size = int(resolution)
86
 
87
- # Password gate
88
- if password != PASSWORD:
89
- return (
90
- [Image.new("RGB", (size, size), "white")],
91
- "❌ Wrong password",
92
- ""
93
- )
94
-
95
  # Placeholder while thinking
96
  yield (
97
  [Image.new("RGB", (size, size), "white")],
98
- "🧠 Enhancing prompt...",
99
- ""
100
  )
101
 
102
  enhanced = enhance_prompt(prompt)
103
 
104
- # Show enhanced prompt immediately
105
  yield (
106
  [Image.new("RGB", (size, size), "white")],
107
- "🎨 Generating image...",
108
- enhanced
109
  )
110
 
111
  seed = random.randint(0, 1_000_000_000)
@@ -125,20 +104,18 @@ def generate(password, prompt, negative, resolution, steps):
125
  ).images[0]
126
  elapsed = int(time.time() - start)
127
 
128
- # Blur reveal (UI-only)
129
  for i in range(10):
130
  blur = image.filter(ImageFilter.GaussianBlur(radius=(10 - i)))
131
  yield (
132
  [blur],
133
- f"👀 Revealing... ({i+1}/10)",
134
- enhanced
135
  )
136
  time.sleep(1)
137
 
138
  yield (
139
  [image],
140
- f"✅ Done in {elapsed}s | Seed {seed}",
141
- enhanced
142
  )
143
 
144
  # ===============================
@@ -148,12 +125,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
148
  gr.Markdown("# 👾 Creeper AI — Image Generator")
149
  gr.Markdown(
150
  "1️⃣ The higher the resolution & steps, the longer the image takes.\n\n"
151
- "2️⃣ More detailed prompts = better results."
152
  )
153
 
154
  with gr.Row():
155
  with gr.Column():
156
- password = gr.Textbox(label="Password", type="password")
157
  prompt = gr.Textbox(label="Prompt")
158
  negative = gr.Textbox(label="Negative Prompt")
159
 
@@ -164,10 +140,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
164
  generate_btn = gr.Button("Generate")
165
 
166
  status = gr.Markdown("🟢 Ready")
167
- enhanced_box = gr.Textbox(
168
- label="Enhanced Prompt (exact output from text AI)",
169
- interactive=False
170
- )
171
 
172
  with gr.Column():
173
  gallery = gr.Gallery(columns=1)
@@ -177,8 +149,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
177
 
178
  generate_btn.click(
179
  generate,
180
- inputs=[password, prompt, negative, resolution, steps],
181
- outputs=[gallery, status, enhanced_box]
182
  )
183
 
184
  demo.launch()
 
6
  from diffusers import DiffusionPipeline, LCMScheduler
7
  from PIL import Image, ImageFilter
8
 
 
 
 
 
 
9
  # ===============================
10
  # TEXT MODEL (PROMPT ENHANCER)
11
  # ===============================
 
15
  text_model = AutoModelForCausalLM.from_pretrained(TEXT_MODEL_ID)
16
 
17
  def enhance_prompt(user_prompt: str) -> str:
 
 
 
 
18
  instruction = (
19
  "Please enhance this prompt so it is suitable for an image generator "
20
  "that requires clear instructions. Analyse the prompt, and output as "
 
33
 
34
  decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
35
 
 
36
  if "Enhanced prompt:" in decoded:
37
  decoded = decoded.split("Enhanced prompt:")[-1]
38
 
 
71
  # ===============================
72
  # GENERATION FUNCTION
73
  # ===============================
74
+ def generate(prompt, negative, resolution, steps):
75
  size = int(resolution)
76
 
 
 
 
 
 
 
 
 
77
  # Placeholder while thinking
78
  yield (
79
  [Image.new("RGB", (size, size), "white")],
80
+ "🧠 Enhancing prompt..."
 
81
  )
82
 
83
  enhanced = enhance_prompt(prompt)
84
 
 
85
  yield (
86
  [Image.new("RGB", (size, size), "white")],
87
+ "🎨 Generating image..."
 
88
  )
89
 
90
  seed = random.randint(0, 1_000_000_000)
 
104
  ).images[0]
105
  elapsed = int(time.time() - start)
106
 
107
+ # Blur reveal
108
  for i in range(10):
109
  blur = image.filter(ImageFilter.GaussianBlur(radius=(10 - i)))
110
  yield (
111
  [blur],
112
+ f"👀 Revealing... ({i+1}/10)"
 
113
  )
114
  time.sleep(1)
115
 
116
  yield (
117
  [image],
118
+ f"✅ Done in {elapsed}s | Seed {seed}"
 
119
  )
120
 
121
  # ===============================
 
125
  gr.Markdown("# 👾 Creeper AI — Image Generator")
126
  gr.Markdown(
127
  "1️⃣ The higher the resolution & steps, the longer the image takes.\n\n"
128
+ "2️⃣ The more detailed the prompt and negative prompt, the better the result."
129
  )
130
 
131
  with gr.Row():
132
  with gr.Column():
 
133
  prompt = gr.Textbox(label="Prompt")
134
  negative = gr.Textbox(label="Negative Prompt")
135
 
 
140
  generate_btn = gr.Button("Generate")
141
 
142
  status = gr.Markdown("🟢 Ready")
 
 
 
 
143
 
144
  with gr.Column():
145
  gallery = gr.Gallery(columns=1)
 
149
 
150
  generate_btn.click(
151
  generate,
152
+ inputs=[prompt, negative, resolution, steps],
153
+ outputs=[gallery, status]
154
  )
155
 
156
  demo.launch()