Equityone commited on
Commit
e75d67a
·
verified ·
1 Parent(s): 5bfd1e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py CHANGED
@@ -112,6 +112,61 @@ COMPOSITION_PARAMS = {
112
  "Néon": "neon color palette, vibrant glowing colors"
113
  }
114
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  class ImageGenerator:
117
  def __init__(self):
 
112
  "Néon": "neon color palette, vibrant glowing colors"
113
  }
114
  }
115
+ class GenerationManager:
116
+ def __init__(self):
117
+ self.save_dir = Path("generations")
118
+ self.save_dir.mkdir(exist_ok=True)
119
+ self.history_file = self.save_dir / "history.json"
120
+ self.history = self.load_history()
121
+ logger.info("Système de génération initialisé")
122
+
123
+ def load_history(self):
124
+ if self.history_file.exists():
125
+ try:
126
+ with open(self.history_file, "r", encoding="utf-8") as f:
127
+ return json.load(f)
128
+ except Exception as e:
129
+ logger.error(f"Erreur chargement historique: {e}")
130
+ return []
131
+ return []
132
+
133
+ def save_generation(self, image, params):
134
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
135
+ image_name = f"generation_{timestamp}.png"
136
+ image_path = self.save_dir / image_name
137
+
138
+ try:
139
+ # Sauvegarde de l'image
140
+ image.save(image_path)
141
+
142
+ # Création de l'entrée
143
+ entry = {
144
+ "id": timestamp,
145
+ "image_path": str(image_path),
146
+ "params": params,
147
+ "created_at": timestamp
148
+ }
149
+
150
+ self.history.append(entry)
151
+ self._save_history()
152
+ return entry
153
+ except Exception as e:
154
+ logger.error(f"Erreur sauvegarde génération: {e}")
155
+ return None
156
+
157
+ def _save_history(self):
158
+ try:
159
+ with open(self.history_file, "w", encoding="utf-8") as f:
160
+ json.dump(self.history, f, indent=2, ensure_ascii=False)
161
+ except Exception as e:
162
+ logger.error(f"Erreur sauvegarde historique: {e}")
163
+
164
+ def get_recent_generations(self, limit=10):
165
+ return sorted(
166
+ self.history,
167
+ key=lambda x: x["created_at"],
168
+ reverse=True
169
+ )[:limit]
170
 
171
  class ImageGenerator:
172
  def __init__(self):