Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
import time
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -85,7 +87,7 @@ def text_to_image(prompt, steps, guidance_scale):
|
|
| 85 |
end_time = time.time()
|
| 86 |
print(f"✅ Bild generiert in {end_time - start_time:.2f} Sekunden")
|
| 87 |
|
| 88 |
-
return image
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
print(f"❌ Fehler: {e}")
|
|
@@ -121,7 +123,27 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale):
|
|
| 121 |
end_time = time.time()
|
| 122 |
print(f"✅ Bild transformiert in {end_time - start_time:.2f} Sekunden")
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
except Exception as e:
|
| 127 |
print(f"❌ Fehler: {e}")
|
|
@@ -247,6 +269,4 @@ app.launch(
|
|
| 247 |
server_port=7860,
|
| 248 |
max_file_size="10MB",
|
| 249 |
show_error=True
|
| 250 |
-
# enable_queue ist bereits standardmäßig True
|
| 251 |
-
# prevent_thread_lock wird nicht benötigt
|
| 252 |
)
|
|
|
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
import time
|
| 6 |
+
import os
|
| 7 |
+
import tempfile
|
| 8 |
|
| 9 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 87 |
end_time = time.time()
|
| 88 |
print(f"✅ Bild generiert in {end_time - start_time:.2f} Sekunden")
|
| 89 |
|
| 90 |
+
return image # Direkte Rückgabe aus RAM
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
print(f"❌ Fehler: {e}")
|
|
|
|
| 123 |
end_time = time.time()
|
| 124 |
print(f"✅ Bild transformiert in {end_time - start_time:.2f} Sekunden")
|
| 125 |
|
| 126 |
+
generated_image = result.images[0] # Bild aus RAM
|
| 127 |
+
|
| 128 |
+
# === TEMP-SPEICHERUNG ALS FALLBACK ===
|
| 129 |
+
try:
|
| 130 |
+
# Erstelle Temp-Verzeichnis falls nicht vorhanden
|
| 131 |
+
temp_dir = "/tmp/gradio_fallback"
|
| 132 |
+
os.makedirs(temp_dir, exist_ok=True)
|
| 133 |
+
|
| 134 |
+
# Speichere Bild temporär
|
| 135 |
+
temp_path = os.path.join(temp_dir, f"generated_{int(time.time())}.png")
|
| 136 |
+
generated_image.save(temp_path, "PNG")
|
| 137 |
+
print(f"💾 Bild temporär gespeichert: {temp_path}")
|
| 138 |
+
|
| 139 |
+
# Lade Bild wieder für konsistente Rückgabe
|
| 140 |
+
saved_image = Image.open(temp_path)
|
| 141 |
+
|
| 142 |
+
except Exception as temp_error:
|
| 143 |
+
print(f"⚠️ Temp-Speicherung fehlgeschlagen: {temp_error}")
|
| 144 |
+
saved_image = generated_image # Fallback auf RAM-Bild
|
| 145 |
+
|
| 146 |
+
return saved_image # Rückgabe des gespeicherten oder RAM-Bildes
|
| 147 |
|
| 148 |
except Exception as e:
|
| 149 |
print(f"❌ Fehler: {e}")
|
|
|
|
| 269 |
server_port=7860,
|
| 270 |
max_file_size="10MB",
|
| 271 |
show_error=True
|
|
|
|
|
|
|
| 272 |
)
|