Update app.py
Browse files
app.py
CHANGED
@@ -153,24 +153,32 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
|
|
153 |
successful_prompts = []
|
154 |
failed_prompts = []
|
155 |
target_images = 10
|
156 |
-
max_attempts_per_image = 3
|
|
|
157 |
|
158 |
# Generate initial batch of prompts
|
159 |
-
optimized_prompts = generate_multiple_prompts(prompt, system_prompt)
|
|
|
|
|
160 |
|
161 |
# Proses setiap target gambar
|
162 |
for i in range(target_images):
|
163 |
attempts = 0
|
164 |
success = False
|
165 |
|
166 |
-
# Retry untuk gambar individual ini
|
167 |
while attempts < max_attempts_per_image and not success:
|
168 |
try:
|
169 |
-
#
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
current_prompt = optimized_prompts[i + attempts]
|
174 |
img, used_prompt = generate_image_with_fallback(current_prompt)
|
175 |
|
176 |
if img is not None:
|
@@ -184,7 +192,6 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
|
|
184 |
failed_prompts.append(f"{current_prompt} (Error: {str(e)})")
|
185 |
attempts += 1
|
186 |
|
187 |
-
# Jika masih gagal setelah max attempts
|
188 |
if not success:
|
189 |
failed_prompts.append(f"Failed after {max_attempts_per_image} attempts for image #{i+1}")
|
190 |
|
|
|
153 |
successful_prompts = []
|
154 |
failed_prompts = []
|
155 |
target_images = 10
|
156 |
+
max_attempts_per_image = 3
|
157 |
+
used_prompts = set() # Untuk tracking prompt yang sudah digunakan
|
158 |
|
159 |
# Generate initial batch of prompts
|
160 |
+
optimized_prompts = [p.strip() for p in generate_multiple_prompts(prompt, system_prompt)]
|
161 |
+
# Hilangkan duplikat dari batch awal
|
162 |
+
optimized_prompts = list(dict.fromkeys(optimized_prompts))
|
163 |
|
164 |
# Proses setiap target gambar
|
165 |
for i in range(target_images):
|
166 |
attempts = 0
|
167 |
success = False
|
168 |
|
|
|
169 |
while attempts < max_attempts_per_image and not success:
|
170 |
try:
|
171 |
+
# Cek apakah perlu generate prompt baru
|
172 |
+
while len(optimized_prompts) <= i + attempts or all(p in used_prompts for p in optimized_prompts):
|
173 |
+
new_prompts = [p.strip() for p in generate_multiple_prompts(prompt, system_prompt)]
|
174 |
+
# Hanya tambahkan prompt yang belum pernah digunakan
|
175 |
+
new_prompts = [p for p in new_prompts if p not in used_prompts]
|
176 |
+
optimized_prompts.extend(new_prompts)
|
177 |
+
|
178 |
+
# Ambil prompt yang belum digunakan
|
179 |
+
current_prompt = next(p for p in optimized_prompts if p not in used_prompts)
|
180 |
+
used_prompts.add(current_prompt) # Tandai sebagai sudah digunakan
|
181 |
|
|
|
182 |
img, used_prompt = generate_image_with_fallback(current_prompt)
|
183 |
|
184 |
if img is not None:
|
|
|
192 |
failed_prompts.append(f"{current_prompt} (Error: {str(e)})")
|
193 |
attempts += 1
|
194 |
|
|
|
195 |
if not success:
|
196 |
failed_prompts.append(f"Failed after {max_attempts_per_image} attempts for image #{i+1}")
|
197 |
|