Spaces:
Paused
Paused
CryptoCreeper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,47 +59,42 @@ def estimate_time(steps, resolution):
|
|
| 59 |
return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
|
| 60 |
|
| 61 |
# -------------------------------
|
| 62 |
-
# IMAGE GENERATION WITH PROGRESSIVE BLUR
|
| 63 |
# -------------------------------
|
| 64 |
def generate(prompt, resolution, steps):
|
| 65 |
# --- THINKING PHASE ---
|
| 66 |
-
start_time = time.time()
|
| 67 |
-
yield None, "🧠 Understanding your prompt..."
|
| 68 |
refined_prompt, neg_prompt = refine_prompt_fast(prompt)
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# --- GENERATION 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,
|
| 79 |
num_inference_steps=int(steps),
|
| 80 |
guidance_scale=1.2,
|
| 81 |
-
width=
|
| 82 |
-
height=
|
| 83 |
generator=gen
|
| 84 |
).images[0]
|
| 85 |
|
| 86 |
# --- PROGRESSIVE BLUR REVEAL ---
|
| 87 |
-
#
|
| 88 |
-
|
| 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],
|
| 99 |
time.sleep(1) # 1 second per step
|
| 100 |
|
| 101 |
-
|
| 102 |
-
yield [img],
|
| 103 |
|
| 104 |
# -------------------------------
|
| 105 |
# GRADIO UI
|
|
@@ -119,16 +114,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 119 |
gen_btn = gr.Button("Generate")
|
| 120 |
|
| 121 |
with gr.Column():
|
| 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 |
-
|
|
|
|
| 128 |
gen_btn.click(
|
| 129 |
generate,
|
| 130 |
inputs=[prompt_in, resolution, steps],
|
| 131 |
-
outputs=[gallery,
|
| 132 |
)
|
| 133 |
|
| 134 |
demo.launch()
|
|
|
|
| 59 |
return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
|
| 60 |
|
| 61 |
# -------------------------------
|
| 62 |
+
# IMAGE GENERATION WITH PROGRESSIVE BLUR GALLERY
|
| 63 |
# -------------------------------
|
| 64 |
def generate(prompt, resolution, steps):
|
| 65 |
# --- THINKING PHASE ---
|
|
|
|
|
|
|
| 66 |
refined_prompt, neg_prompt = refine_prompt_fast(prompt)
|
| 67 |
+
|
| 68 |
+
# --- SHOW WHITE IMAGE WHILE GENERATING ---
|
| 69 |
+
width, height = int(resolution), int(resolution)
|
| 70 |
+
blank_img = Image.new("RGB", (width, height), (255, 255, 255))
|
| 71 |
+
yield [blank_img], "" # always show gallery placeholder
|
| 72 |
|
| 73 |
# --- GENERATION PHASE ---
|
| 74 |
seed = random.randint(0, 10**9)
|
| 75 |
gen = torch.Generator("cpu").manual_seed(seed)
|
|
|
|
| 76 |
pipe.scheduler.set_timesteps(int(steps))
|
| 77 |
img = pipe(
|
| 78 |
prompt=refined_prompt,
|
| 79 |
negative_prompt=neg_prompt,
|
| 80 |
num_inference_steps=int(steps),
|
| 81 |
guidance_scale=1.2,
|
| 82 |
+
width=width,
|
| 83 |
+
height=height,
|
| 84 |
generator=gen
|
| 85 |
).images[0]
|
| 86 |
|
| 87 |
# --- PROGRESSIVE BLUR REVEAL ---
|
| 88 |
+
max_blur = 20 # max blur radius for 100%
|
| 89 |
+
steps_blur = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
for i in range(steps_blur):
|
| 91 |
blur_percent = 100 - i*10
|
| 92 |
blurred_img = img.filter(ImageFilter.GaussianBlur(radius=max_blur * blur_percent / 100))
|
| 93 |
+
yield [blurred_img], "" # gallery updated, no status text
|
| 94 |
time.sleep(1) # 1 second per step
|
| 95 |
|
| 96 |
+
# --- FINAL IMAGE ---
|
| 97 |
+
yield [img], "" # fully revealed image
|
| 98 |
|
| 99 |
# -------------------------------
|
| 100 |
# GRADIO UI
|
|
|
|
| 114 |
gen_btn = gr.Button("Generate")
|
| 115 |
|
| 116 |
with gr.Column():
|
|
|
|
| 117 |
gallery = gr.Gallery(columns=1)
|
| 118 |
+
|
| 119 |
+
# Update ETA dynamically
|
| 120 |
for ctrl in [steps, resolution]:
|
| 121 |
ctrl.change(estimate_time, [steps, resolution], eta)
|
| 122 |
+
|
| 123 |
+
# Button click triggers generation
|
| 124 |
gen_btn.click(
|
| 125 |
generate,
|
| 126 |
inputs=[prompt_in, resolution, steps],
|
| 127 |
+
outputs=[gallery, gallery] # gallery updated for progressive blur
|
| 128 |
)
|
| 129 |
|
| 130 |
demo.launch()
|