Astridkraft commited on
Commit
6ec1fba
·
verified ·
1 Parent(s): 8e4595c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -104,18 +104,19 @@ def load_img2img():
104
 
105
  return pipe_img2img
106
 
107
- # === CALLBACK-FUNKTIONEN FÜR FORTSCHRITT ===
108
  class TextToImageProgressCallback:
109
  def __init__(self, progress, total_steps):
110
  self.progress = progress
111
  self.total_steps = total_steps
112
  self.current_step = 0
113
 
114
- def __call__(self, step, timestep, latents):
 
115
  self.current_step = step + 1
116
  progress_percent = (step / self.total_steps) * 100
117
  self.progress(progress_percent / 100, desc="Generierung läuft - CPU benötigt bis zu 6 Minuten!")
118
- return False
119
 
120
  class ImageToImageProgressCallback:
121
  def __init__(self, progress, total_steps, strength):
@@ -125,7 +126,8 @@ class ImageToImageProgressCallback:
125
  self.strength = strength
126
  self.actual_total_steps = None
127
 
128
- def __call__(self, step, timestep, latents):
 
129
  self.current_step = step + 1
130
 
131
  # Korrekte Berechnung der tatsächlichen Steps
@@ -140,8 +142,7 @@ class ImageToImageProgressCallback:
140
 
141
  progress_percent = (step / self.actual_total_steps) * 100
142
  self.progress(progress_percent / 100, desc="Generierung läuft - CPU benötigt bis zu 8 Minuten!")
143
- #self.progress(progress_percent / 100, desc=f"Schritt {self.current_step}/{self.actual_total_steps} - {progress_percent:.1f}%")
144
- return False
145
 
146
  # === FUNKTIONEN ===
147
  def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
@@ -162,7 +163,7 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
162
  generator = torch.Generator(device=device).manual_seed(seed)
163
  print(f"Using seed: {seed}")
164
 
165
- # Progress Callback hinzufügen
166
  callback = TextToImageProgressCallback(progress, steps)
167
 
168
  image = pipe(
@@ -172,8 +173,8 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
172
  num_inference_steps=steps,
173
  guidance_scale=guidance_scale,
174
  generator=generator,
175
- callback=callback,
176
- callback_steps=1
177
  ).images[0]
178
 
179
  end_time = time.time()
@@ -253,10 +254,10 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
253
  actual_steps_from_strength = int(steps * adj_strength)
254
  print(f"🎯 KORREKTE INTERNE STEP-AUSGABE: {int(steps)} Steps × Strength {adj_strength:.3f} = {actual_steps_from_strength} tatsächliche Schritte")
255
 
256
- # Progress Callback hinzufügen
257
  callback = ImageToImageProgressCallback(progress, int(steps), adj_strength)
258
 
259
- # --- PIPELINE-AUFRUF ---
260
  result = pipe(
261
  prompt=prompt,
262
  negative_prompt=neg_prompt,
@@ -266,8 +267,8 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
266
  num_inference_steps=int(steps),
267
  guidance_scale=adj_guidance,
268
  generator=generator,
269
- callback=callback,
270
- callback_steps=1
271
  )
272
 
273
  # ZUSÄTZLICHE AUSGABE: Tatsächliche Steps vom Scheduler - Inpaint berechnet steps intern. Max_step ist aus UI-Übergabe.
 
104
 
105
  return pipe_img2img
106
 
107
+ # === NEUE CALLBACK-FUNKTIONEN FÜR FORTSCHRITT (kompatibel mit neuer API) ===
108
  class TextToImageProgressCallback:
109
  def __init__(self, progress, total_steps):
110
  self.progress = progress
111
  self.total_steps = total_steps
112
  self.current_step = 0
113
 
114
+ def __call__(self, pipe, step, timestep, callback_kwargs):
115
+ """Neue Callback-Signatur für diffusers >= 1.0.0"""
116
  self.current_step = step + 1
117
  progress_percent = (step / self.total_steps) * 100
118
  self.progress(progress_percent / 100, desc="Generierung läuft - CPU benötigt bis zu 6 Minuten!")
119
+ return callback_kwargs
120
 
121
  class ImageToImageProgressCallback:
122
  def __init__(self, progress, total_steps, strength):
 
126
  self.strength = strength
127
  self.actual_total_steps = None
128
 
129
+ def __call__(self, pipe, step, timestep, callback_kwargs):
130
+ """Neue Callback-Signatur für diffusers >= 1.0.0"""
131
  self.current_step = step + 1
132
 
133
  # Korrekte Berechnung der tatsächlichen Steps
 
142
 
143
  progress_percent = (step / self.actual_total_steps) * 100
144
  self.progress(progress_percent / 100, desc="Generierung läuft - CPU benötigt bis zu 8 Minuten!")
145
+ return callback_kwargs
 
146
 
147
  # === FUNKTIONEN ===
148
  def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
 
163
  generator = torch.Generator(device=device).manual_seed(seed)
164
  print(f"Using seed: {seed}")
165
 
166
+ # NEUE Callback-Implementierung
167
  callback = TextToImageProgressCallback(progress, steps)
168
 
169
  image = pipe(
 
173
  num_inference_steps=steps,
174
  guidance_scale=guidance_scale,
175
  generator=generator,
176
+ callback_on_step_end=callback, # NEUE Parameter-Name
177
+ callback_on_step_end_tensor_inputs=[], # Keine zusätzlichen Tensor-Inputs
178
  ).images[0]
179
 
180
  end_time = time.time()
 
254
  actual_steps_from_strength = int(steps * adj_strength)
255
  print(f"🎯 KORREKTE INTERNE STEP-AUSGABE: {int(steps)} Steps × Strength {adj_strength:.3f} = {actual_steps_from_strength} tatsächliche Schritte")
256
 
257
+ # NEUE Callback-Implementierung
258
  callback = ImageToImageProgressCallback(progress, int(steps), adj_strength)
259
 
260
+ # --- PIPELINE-AUFRUF MIT NEUER API ---
261
  result = pipe(
262
  prompt=prompt,
263
  negative_prompt=neg_prompt,
 
267
  num_inference_steps=int(steps),
268
  guidance_scale=adj_guidance,
269
  generator=generator,
270
+ callback_on_step_end=callback, # NEUE Parameter-Name
271
+ callback_on_step_end_tensor_inputs=[], # Keine zusätzlichen Tensor-Inputs
272
  )
273
 
274
  # ZUSÄTZLICHE AUSGABE: Tatsächliche Steps vom Scheduler - Inpaint berechnet steps intern. Max_step ist aus UI-Übergabe.