Spaces:
Paused
Paused
CryptoCreeper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import torch
|
|
| 3 |
import random
|
| 4 |
import time
|
| 5 |
from diffusers import DiffusionPipeline, LCMScheduler
|
|
|
|
| 6 |
|
| 7 |
# -------------------------------
|
| 8 |
# MODEL SETUP (CPU SAFE)
|
|
@@ -30,12 +31,10 @@ def refine_prompt_fast(user_prompt: str):
|
|
| 30 |
"""
|
| 31 |
Instant deterministic prompt refinement (<1ms)
|
| 32 |
"""
|
| 33 |
-
# Known objects
|
| 34 |
known_objects = {"apple","banana","snake","cat","dog","fox","rabbit","dragon","bird","frog","hamster"}
|
| 35 |
object_found = next((w for w in known_objects if w in user_prompt.lower()), None)
|
| 36 |
subject = object_found if object_found else user_prompt.lower().strip()
|
| 37 |
|
| 38 |
-
# Style detection
|
| 39 |
style = ""
|
| 40 |
if any(w in user_prompt.lower() for w in ["cute","adorable","kawaii"]):
|
| 41 |
style = ", cute, friendly, rounded body, big eyes, pastel colors, cartoon style"
|
|
@@ -44,12 +43,8 @@ def refine_prompt_fast(user_prompt: str):
|
|
| 44 |
else:
|
| 45 |
style = ", high quality, clean background"
|
| 46 |
|
| 47 |
-
# Construct prompt
|
| 48 |
prompt = f"a single {subject}, centered, isolated{style}"
|
| 49 |
-
|
| 50 |
-
# Negative prompt (always same)
|
| 51 |
negative = "multiple objects, duplicate, blurry, low quality, cropped, out of frame, horror, grotesque, aggressive, weird colors, artifacts"
|
| 52 |
-
|
| 53 |
return prompt, negative
|
| 54 |
|
| 55 |
# -------------------------------
|
|
@@ -57,14 +52,14 @@ def refine_prompt_fast(user_prompt: str):
|
|
| 57 |
# -------------------------------
|
| 58 |
def estimate_time(steps, resolution):
|
| 59 |
per_step = {256:6, 512:12, 768:25, 1024:45}[int(resolution)]
|
| 60 |
-
overhead = 2
|
| 61 |
est = overhead + steps * per_step
|
| 62 |
minutes = est // 60
|
| 63 |
seconds = est % 60
|
| 64 |
return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
|
| 65 |
|
| 66 |
# -------------------------------
|
| 67 |
-
# IMAGE GENERATION WITH
|
| 68 |
# -------------------------------
|
| 69 |
def generate(prompt, resolution, steps):
|
| 70 |
# --- THINKING PHASE ---
|
|
@@ -77,7 +72,7 @@ def generate(prompt, resolution, steps):
|
|
| 77 |
seed = random.randint(0, 10**9)
|
| 78 |
gen = torch.Generator("cpu").manual_seed(seed)
|
| 79 |
|
| 80 |
-
pipe.scheduler.set_timesteps(int(steps))
|
| 81 |
img = pipe(
|
| 82 |
prompt=refined_prompt,
|
| 83 |
negative_prompt=neg_prompt,
|
|
@@ -88,6 +83,21 @@ def generate(prompt, resolution, steps):
|
|
| 88 |
generator=gen
|
| 89 |
).images[0]
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
duration = int(time.time() - start_time)
|
| 92 |
yield [img], f"✅ Finished in {duration}s | Seed: {seed}"
|
| 93 |
|
|
@@ -96,7 +106,7 @@ def generate(prompt, resolution, steps):
|
|
| 96 |
# -------------------------------
|
| 97 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 98 |
gr.Markdown("# 👾 CREEPER AI — CPU SMART IMAGE GENERATION")
|
| 99 |
-
|
| 100 |
with gr.Row():
|
| 101 |
with gr.Column():
|
| 102 |
prompt_in = gr.Textbox(label="Prompt", placeholder="cute snake", lines=2)
|
|
@@ -112,7 +122,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 112 |
status = gr.Markdown("🟢 Ready")
|
| 113 |
gallery = gr.Gallery(columns=1)
|
| 114 |
|
| 115 |
-
# Update ETA dynamically
|
| 116 |
for ctrl in [steps, resolution]:
|
| 117 |
ctrl.change(estimate_time, [steps, resolution], eta)
|
| 118 |
|
|
|
|
| 3 |
import random
|
| 4 |
import time
|
| 5 |
from diffusers import DiffusionPipeline, LCMScheduler
|
| 6 |
+
from PIL import Image, ImageFilter
|
| 7 |
|
| 8 |
# -------------------------------
|
| 9 |
# MODEL SETUP (CPU SAFE)
|
|
|
|
| 31 |
"""
|
| 32 |
Instant deterministic prompt refinement (<1ms)
|
| 33 |
"""
|
|
|
|
| 34 |
known_objects = {"apple","banana","snake","cat","dog","fox","rabbit","dragon","bird","frog","hamster"}
|
| 35 |
object_found = next((w for w in known_objects if w in user_prompt.lower()), None)
|
| 36 |
subject = object_found if object_found else user_prompt.lower().strip()
|
| 37 |
|
|
|
|
| 38 |
style = ""
|
| 39 |
if any(w in user_prompt.lower() for w in ["cute","adorable","kawaii"]):
|
| 40 |
style = ", cute, friendly, rounded body, big eyes, pastel colors, cartoon style"
|
|
|
|
| 43 |
else:
|
| 44 |
style = ", high quality, clean background"
|
| 45 |
|
|
|
|
| 46 |
prompt = f"a single {subject}, centered, isolated{style}"
|
|
|
|
|
|
|
| 47 |
negative = "multiple objects, duplicate, blurry, low quality, cropped, out of frame, horror, grotesque, aggressive, weird colors, artifacts"
|
|
|
|
| 48 |
return prompt, negative
|
| 49 |
|
| 50 |
# -------------------------------
|
|
|
|
| 52 |
# -------------------------------
|
| 53 |
def estimate_time(steps, resolution):
|
| 54 |
per_step = {256:6, 512:12, 768:25, 1024:45}[int(resolution)]
|
| 55 |
+
overhead = 2
|
| 56 |
est = overhead + steps * per_step
|
| 57 |
minutes = est // 60
|
| 58 |
seconds = est % 60
|
| 59 |
return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
|
| 60 |
|
| 61 |
# -------------------------------
|
| 62 |
+
# IMAGE GENERATION WITH PROGRESSIVE BLUR REVEAL
|
| 63 |
# -------------------------------
|
| 64 |
def generate(prompt, resolution, steps):
|
| 65 |
# --- THINKING PHASE ---
|
|
|
|
| 72 |
seed = random.randint(0, 10**9)
|
| 73 |
gen = torch.Generator("cpu").manual_seed(seed)
|
| 74 |
|
| 75 |
+
pipe.scheduler.set_timesteps(int(steps))
|
| 76 |
img = pipe(
|
| 77 |
prompt=refined_prompt,
|
| 78 |
negative_prompt=neg_prompt,
|
|
|
|
| 83 |
generator=gen
|
| 84 |
).images[0]
|
| 85 |
|
| 86 |
+
# --- PROGRESSIVE BLUR REVEAL ---
|
| 87 |
+
# First show white placeholder
|
| 88 |
+
width, height = img.size
|
| 89 |
+
white_img = Image.new("RGB", (width, height), (255, 255, 255))
|
| 90 |
+
yield [white_img], "🖼 Image generated! Revealing..."
|
| 91 |
+
|
| 92 |
+
# Apply progressive blur
|
| 93 |
+
max_blur = 20 # max blur radius
|
| 94 |
+
steps_blur = 10 # number of steps
|
| 95 |
+
for i in range(steps_blur):
|
| 96 |
+
blur_percent = 100 - i*10
|
| 97 |
+
blurred_img = img.filter(ImageFilter.GaussianBlur(radius=max_blur * blur_percent / 100))
|
| 98 |
+
yield [blurred_img], f"🖼 Revealing image... {i*10}%"
|
| 99 |
+
time.sleep(1) # 1 second per step
|
| 100 |
+
|
| 101 |
duration = int(time.time() - start_time)
|
| 102 |
yield [img], f"✅ Finished in {duration}s | Seed: {seed}"
|
| 103 |
|
|
|
|
| 106 |
# -------------------------------
|
| 107 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 108 |
gr.Markdown("# 👾 CREEPER AI — CPU SMART IMAGE GENERATION")
|
| 109 |
+
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column():
|
| 112 |
prompt_in = gr.Textbox(label="Prompt", placeholder="cute snake", lines=2)
|
|
|
|
| 122 |
status = gr.Markdown("🟢 Ready")
|
| 123 |
gallery = gr.Gallery(columns=1)
|
| 124 |
|
|
|
|
| 125 |
for ctrl in [steps, resolution]:
|
| 126 |
ctrl.change(estimate_time, [steps, resolution], eta)
|
| 127 |
|