Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio import TempFile
|
| 3 |
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 4 |
from diffusers import StableDiffusionInpaintPipeline
|
| 5 |
import torch
|
|
@@ -105,21 +104,6 @@ def load_img2img():
|
|
| 105 |
|
| 106 |
return pipe_img2img
|
| 107 |
|
| 108 |
-
# === HILFSFUNKTION FÜR ROBUSTE ZWISCHENSPEICHERUNG ===
|
| 109 |
-
temp_file_manager = TempFile()
|
| 110 |
-
|
| 111 |
-
def save_with_fallback(image):
|
| 112 |
-
try:
|
| 113 |
-
with temp_file_manager as temp_file:
|
| 114 |
-
path = temp_file.name
|
| 115 |
-
image.save(path, "PNG")
|
| 116 |
-
print(f"Gradio-Temp gespeichert: {path}")
|
| 117 |
-
return path
|
| 118 |
-
except Exception as e:
|
| 119 |
-
print(f"Temp-Speicherung fehlgeschlagen: {e}")
|
| 120 |
-
return image
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
# === FUNKTIONEN ===
|
| 125 |
def text_to_image(prompt, steps, guidance_scale):
|
|
@@ -150,7 +134,7 @@ def text_to_image(prompt, steps, guidance_scale):
|
|
| 150 |
print(f"Bild generiert in {end_time - start_time:.2f} Sekunden")
|
| 151 |
|
| 152 |
# Robuste Zwischenspeicherung
|
| 153 |
-
return
|
| 154 |
|
| 155 |
except Exception as e:
|
| 156 |
print(f"Fehler: {e}")
|
|
@@ -225,8 +209,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
|
|
| 225 |
|
| 226 |
generated_image = result.images[0]
|
| 227 |
|
| 228 |
-
|
| 229 |
-
return save_with_fallback(generated_image)
|
| 230 |
|
| 231 |
except Exception as e:
|
| 232 |
print(f"Fehler: {e}")
|
|
@@ -368,7 +351,7 @@ def main_ui():
|
|
| 368 |
txt_output = gr.Image(
|
| 369 |
label="Generiertes Bild",
|
| 370 |
show_download_button=True,
|
| 371 |
-
type="
|
| 372 |
)
|
| 373 |
|
| 374 |
generate_btn.click(
|
|
@@ -478,7 +461,7 @@ def main_ui():
|
|
| 478 |
img_output = gr.Image(
|
| 479 |
label="Transformiertes Bild",
|
| 480 |
show_download_button=True,
|
| 481 |
-
type="
|
| 482 |
)
|
| 483 |
|
| 484 |
# Event-Handler für Bild-Upload
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 3 |
from diffusers import StableDiffusionInpaintPipeline
|
| 4 |
import torch
|
|
|
|
| 104 |
|
| 105 |
return pipe_img2img
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# === FUNKTIONEN ===
|
| 109 |
def text_to_image(prompt, steps, guidance_scale):
|
|
|
|
| 134 |
print(f"Bild generiert in {end_time - start_time:.2f} Sekunden")
|
| 135 |
|
| 136 |
# Robuste Zwischenspeicherung
|
| 137 |
+
return image
|
| 138 |
|
| 139 |
except Exception as e:
|
| 140 |
print(f"Fehler: {e}")
|
|
|
|
| 209 |
|
| 210 |
generated_image = result.images[0]
|
| 211 |
|
| 212 |
+
return generated_image
|
|
|
|
| 213 |
|
| 214 |
except Exception as e:
|
| 215 |
print(f"Fehler: {e}")
|
|
|
|
| 351 |
txt_output = gr.Image(
|
| 352 |
label="Generiertes Bild",
|
| 353 |
show_download_button=True,
|
| 354 |
+
type="pil"
|
| 355 |
)
|
| 356 |
|
| 357 |
generate_btn.click(
|
|
|
|
| 461 |
img_output = gr.Image(
|
| 462 |
label="Transformiertes Bild",
|
| 463 |
show_download_button=True,
|
| 464 |
+
type="pil"
|
| 465 |
)
|
| 466 |
|
| 467 |
# Event-Handler für Bild-Upload
|