Astridkraft commited on
Commit
2e71401
·
verified ·
1 Parent(s): 97ef7f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -105,25 +105,23 @@ def load_img2img():
105
  return pipe_img2img
106
 
107
  # === HILFSFUNKTION FÜR ROBUSTE ZWISCHENSPEICHERUNG ===
 
 
 
 
108
  def save_with_fallback(image):
109
  try:
110
- temp_dir = os.getenv("GRADIO_TEMP_DIR") or tempfile.gettempdir()
111
- temp_file = tempfile.NamedTemporaryFile(
112
- suffix=".png",
113
- dir=temp_dir,
114
- delete=False # ← Datei bleibt im HF-Container!
115
- )
116
- path = temp_file.name
117
- temp_file.close()
118
-
119
- image.save(path, "PNG")
120
- print(f"HF-Temp gespeichert: {path}")
121
- return path
122
  except Exception as e:
123
  print(f"Temp-Speicherung fehlgeschlagen: {e}")
124
  return image
125
 
126
 
 
127
  # === FUNKTIONEN ===
128
  def text_to_image(prompt, steps, guidance_scale):
129
  try:
 
105
  return pipe_img2img
106
 
107
  # === HILFSFUNKTION FÜR ROBUSTE ZWISCHENSPEICHERUNG ===
108
+ from gradio import TempFile
109
+
110
+ temp_file_manager = TempFile()
111
+
112
  def save_with_fallback(image):
113
  try:
114
+ with temp_file_manager as temp_file:
115
+ path = temp_file.name
116
+ image.save(path, "PNG")
117
+ print(f"Gradio-Temp gespeichert: {path}")
118
+ return path
 
 
 
 
 
 
 
119
  except Exception as e:
120
  print(f"Temp-Speicherung fehlgeschlagen: {e}")
121
  return image
122
 
123
 
124
+
125
  # === FUNKTIONEN ===
126
  def text_to_image(prompt, steps, guidance_scale):
127
  try: