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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -106,19 +106,19 @@ def load_img2img():
106
 
107
  # === HILFSFUNKTION FÜR ROBUSTE ZWISCHENSPEICHERUNG ===
108
  def save_with_fallback(image):
109
- """Speichert Bild in Gradios EIGENEM Temp-Ordner (fetchbar nach Reconnect)"""
110
  try:
111
- # NUR Gradios echtes Temp-Verzeichnis (KEIN Unterordner!)
112
  temp_dir = os.getenv("GRADIO_TEMP_DIR") or tempfile.gettempdir()
113
- # KEIN os.makedirs! Gradio hat das schon
114
-
115
- fd, path = tempfile.mkstemp(suffix=".png", dir=temp_dir)
116
- os.close(fd)
 
 
 
117
 
118
  image.save(path, "PNG")
119
- print(f"Temp gespeichert: {path}") # ← Debug
120
  return path
121
-
122
  except Exception as e:
123
  print(f"Temp-Speicherung fehlgeschlagen: {e}")
124
  return image
 
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