Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,30 +118,32 @@ class TextToImageProgressCallback:
|
|
| 118 |
return False
|
| 119 |
|
| 120 |
class ImageToImageProgressCallback:
|
| 121 |
-
def __init__(self, progress, total_steps):
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
def __call__(self, step, timestep, latents):
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
except:
|
| 138 |
-
self.actual_total_steps = self.total_steps
|
| 139 |
-
print(f"🎯 INTERNE STEP-AUSGABE: Verwende konfigurierte {self.total_steps} Schritte")
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# === FUNKTIONEN ===
|
| 147 |
def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
@@ -241,20 +243,23 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
|
|
| 241 |
print("Keine gültigen Koordinaten - keine Maske angewendet")
|
| 242 |
mask = None
|
| 243 |
|
|
|
|
| 244 |
# Detaillierte Debug-Informationen vor dem Pipeline-Aufruf
|
| 245 |
print(f"⚙️ PIPELINE-KONFIGURATION:")
|
| 246 |
print(f" - Angefordert: {int(steps)} Steps")
|
| 247 |
-
print(f" - Strength: {adj_strength}")
|
| 248 |
print(f" - Scheduler: {pipe.scheduler.__class__.__name__}")
|
| 249 |
|
| 250 |
-
#
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
print(f"🎯 INTERNE STEP-AUSGABE: Strength {adj_strength} → {actual_inference_steps} tatsächliche Denoising-Schritte")
|
| 255 |
|
|
|
|
|
|
|
|
|
|
| 256 |
# Progress Callback hinzufügen
|
| 257 |
-
callback = ImageToImageProgressCallback(progress, int(steps))
|
| 258 |
|
| 259 |
# --- PIPELINE-AUFRUF ---
|
| 260 |
result = pipe(
|
|
@@ -270,20 +275,21 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
|
|
| 270 |
callback_steps=1
|
| 271 |
)
|
| 272 |
|
|
|
|
| 273 |
# ZUSÄTZLICHE AUSGABE: Tatsächliche Steps vom Scheduler
|
| 274 |
try:
|
| 275 |
-
# Der Scheduler hat Informationen über die tatsächliche Schrittanzahl
|
| 276 |
scheduler = pipe.scheduler
|
| 277 |
print(f"🔧 SCHEDULER-INFO: {scheduler.__class__.__name__}")
|
| 278 |
-
print(f"📊 TATSÄCHLICHE STEP-KONFIGURATION: {int(steps)} Schritte mit Strength {adj_strength}")
|
| 279 |
-
|
| 280 |
-
# Bei einigen Schedulern kann man die Timesteps sehen
|
| 281 |
if hasattr(scheduler, 'timesteps'):
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
except Exception as e:
|
| 286 |
print(f"⚠️ Konnte Scheduler-Info nicht auslesen: {e}")
|
|
|
|
|
|
|
| 287 |
|
| 288 |
end_time = time.time()
|
| 289 |
print(f"Bild transformiert in {end_time - start_time:.2f} Sekunden")
|
|
@@ -607,4 +613,4 @@ if __name__ == "__main__":
|
|
| 607 |
server_port=7860,
|
| 608 |
max_file_size="10MB",
|
| 609 |
show_error=True
|
| 610 |
-
)
|
|
|
|
| 118 |
return False
|
| 119 |
|
| 120 |
class ImageToImageProgressCallback:
|
| 121 |
+
def __init__(self, progress, total_steps, strength):
|
| 122 |
+
self.progress = progress
|
| 123 |
+
self.total_steps = total_steps
|
| 124 |
+
self.current_step = 0
|
| 125 |
+
self.strength = strength
|
| 126 |
+
self.actual_total_steps = None
|
| 127 |
+
|
| 128 |
+
|
| 129 |
def __call__(self, step, timestep, latents):
|
| 130 |
+
self.current_step = step + 1
|
| 131 |
+
|
| 132 |
+
# Korrekte Berechnung der tatsächlichen Steps
|
| 133 |
+
if self.actual_total_steps is None:
|
| 134 |
+
# Bei Strength < 1.0 werden weniger Steps verwendet
|
| 135 |
+
if self.strength < 1.0:
|
| 136 |
+
self.actual_total_steps = int(self.total_steps * self.strength)
|
| 137 |
+
else:
|
| 138 |
+
self.actual_total_steps = self.total_steps
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
print(f"🎯 INTERNE STEP-AUSGABE: Strength {self.strength} → {self.actual_total_steps} tatsächliche Denoising-Schritte")
|
| 141 |
+
|
| 142 |
+
progress_percent = (step / self.actual_total_steps) * 100
|
| 143 |
+
self.progress(progress_percent / 100, desc=f"Schritt {self.current_step}/{self.actual_total_steps} - {progress_percent:.1f}%")
|
| 144 |
+
return False
|
| 145 |
+
|
| 146 |
+
|
| 147 |
|
| 148 |
# === FUNKTIONEN ===
|
| 149 |
def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
|
|
| 243 |
print("Keine gültigen Koordinaten - keine Maske angewendet")
|
| 244 |
mask = None
|
| 245 |
|
| 246 |
+
|
| 247 |
# Detaillierte Debug-Informationen vor dem Pipeline-Aufruf
|
| 248 |
print(f"⚙️ PIPELINE-KONFIGURATION:")
|
| 249 |
print(f" - Angefordert: {int(steps)} Steps")
|
| 250 |
+
print(f" - Strength: {adj_strength:.3f}")
|
| 251 |
print(f" - Scheduler: {pipe.scheduler.__class__.__name__}")
|
| 252 |
|
| 253 |
+
# Korrekte Berechnung der tatsächlichen Steps
|
| 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 |
|
| 258 |
+
|
| 259 |
+
# Progress Callback hinzufügen
|
| 260 |
+
callback = ImageToImageProgressCallback(progress, int(steps), adj_strength)
|
| 261 |
# Progress Callback hinzufügen
|
| 262 |
+
#callback = ImageToImageProgressCallback(progress, int(steps))
|
| 263 |
|
| 264 |
# --- PIPELINE-AUFRUF ---
|
| 265 |
result = pipe(
|
|
|
|
| 275 |
callback_steps=1
|
| 276 |
)
|
| 277 |
|
| 278 |
+
|
| 279 |
# ZUSÄTZLICHE AUSGABE: Tatsächliche Steps vom Scheduler
|
| 280 |
try:
|
|
|
|
| 281 |
scheduler = pipe.scheduler
|
| 282 |
print(f"🔧 SCHEDULER-INFO: {scheduler.__class__.__name__}")
|
| 283 |
+
print(f"📊 TATSÄCHLICHE STEP-KONFIGURATION: {int(steps)} Schritte mit Strength {adj_strength:.3f}")
|
| 284 |
+
|
|
|
|
| 285 |
if hasattr(scheduler, 'timesteps'):
|
| 286 |
+
actual_steps = len(scheduler.timesteps)
|
| 287 |
+
print(f"🎯 BESTÄTIGTE INTERNE STEP-AUSGABE: Scheduler verwendete {actual_steps} tatsächliche Denoising-Schritte")
|
| 288 |
+
|
| 289 |
except Exception as e:
|
| 290 |
print(f"⚠️ Konnte Scheduler-Info nicht auslesen: {e}")
|
| 291 |
+
|
| 292 |
+
|
| 293 |
|
| 294 |
end_time = time.time()
|
| 295 |
print(f"Bild transformiert in {end_time - start_time:.2f} Sekunden")
|
|
|
|
| 613 |
server_port=7860,
|
| 614 |
max_file_size="10MB",
|
| 615 |
show_error=True
|
| 616 |
+
)
|