CryptoCreeper commited on
Commit
92d864d
·
verified ·
1 Parent(s): 6c18e01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -27
app.py CHANGED
@@ -3,7 +3,7 @@ import torch
3
  import random
4
  import time
5
  from diffusers import DiffusionPipeline, LCMScheduler
6
- from PIL import Image, ImageDraw, ImageFont, ImageFilter
7
 
8
  # -------------------------------
9
  # MODEL SETUP (CPU SAFE)
@@ -50,24 +50,6 @@ def estimate_time(steps, resolution):
50
  seconds = est % 60
51
  return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
52
 
53
- # -------------------------------
54
- # GENERATING PLACEHOLDER IMAGE
55
- # -------------------------------
56
- def generating_placeholder(resolution):
57
- resolution = int(resolution)
58
- img = Image.new("RGB", (resolution, resolution), (30, 30, 30)) # dark background
59
- draw = ImageDraw.Draw(img)
60
- text = "Generating..."
61
- try:
62
- font = ImageFont.truetype("arial.ttf", resolution // 12)
63
- except:
64
- font = ImageFont.load_default()
65
- text_width, text_height = draw.textsize(text, font=font)
66
- x = (resolution - text_width) / 2
67
- y = (resolution - text_height) / 2
68
- draw.text((x, y), text, fill=(255, 255, 255), font=font)
69
- return img
70
-
71
  # -------------------------------
72
  # IMAGE GENERATION WITH PROGRESSIVE BLUR
73
  # -------------------------------
@@ -78,9 +60,10 @@ def generate(prompt, resolution, steps):
78
  # 1️⃣ Refine prompt
79
  refined_prompt, neg_prompt = refine_prompt(prompt)
80
 
81
- # 2️⃣ Show "Generating..." placeholder
82
- placeholder = generating_placeholder(resolution)
83
- yield [placeholder]
 
84
 
85
  # 3️⃣ CPU Image generation
86
  seed = random.randint(0, 10**9)
@@ -103,11 +86,13 @@ def generate(prompt, resolution, steps):
103
  for i in range(steps_blur):
104
  blur_percent = 100 - i*10
105
  blurred_img = img.filter(ImageFilter.GaussianBlur(radius=max_blur * blur_percent / 100))
106
- yield [blurred_img]
107
- time.sleep(1) # 1 second per step
 
108
 
109
- # 5️⃣ Fully revealed image
110
- yield [img]
 
111
 
112
  # -------------------------------
113
  # GRADIO UI
@@ -126,6 +111,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
126
  eta = gr.Markdown("⏱️ Estimated time: ~1m 0s")
127
  gen_btn = gr.Button("Generate")
128
 
 
 
129
  with gr.Column():
130
  gallery = gr.Gallery(columns=1)
131
 
@@ -137,7 +124,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
137
  gen_btn.click(
138
  generate,
139
  inputs=[prompt_in, resolution, steps],
140
- outputs=[gallery]
141
  )
142
 
143
  demo.launch()
 
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)
 
50
  seconds = est % 60
51
  return f"⏱️ Estimated time: ~{int(minutes)}m {int(seconds)}s"
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # -------------------------------
54
  # IMAGE GENERATION WITH PROGRESSIVE BLUR
55
  # -------------------------------
 
60
  # 1️⃣ Refine prompt
61
  refined_prompt, neg_prompt = refine_prompt(prompt)
62
 
63
+ # 2️⃣ White placeholder image
64
+ placeholder = Image.new("RGB", (resolution, resolution), (255, 255, 255))
65
+ start_time = time.time()
66
+ yield [placeholder], "🟡 Generating..."
67
 
68
  # 3️⃣ CPU Image generation
69
  seed = random.randint(0, 10**9)
 
86
  for i in range(steps_blur):
87
  blur_percent = 100 - i*10
88
  blurred_img = img.filter(ImageFilter.GaussianBlur(radius=max_blur * blur_percent / 100))
89
+ yield [blurred_img], "🟢 Generating..."
90
+
91
+ time.sleep(1)
92
 
93
+ # 5️⃣ Final image with total time
94
+ total_time = round(time.time() - start_time, 2)
95
+ yield [img], f"✅ Done in {total_time}s"
96
 
97
  # -------------------------------
98
  # GRADIO UI
 
111
  eta = gr.Markdown("⏱️ Estimated time: ~1m 0s")
112
  gen_btn = gr.Button("Generate")
113
 
114
+ status = gr.Markdown("🟢 Ready")
115
+
116
  with gr.Column():
117
  gallery = gr.Gallery(columns=1)
118
 
 
124
  gen_btn.click(
125
  generate,
126
  inputs=[prompt_in, resolution, steps],
127
+ outputs=[gallery, status]
128
  )
129
 
130
  demo.launch()