Update app.py
Browse files
app.py
CHANGED
@@ -152,33 +152,53 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
|
|
152 |
images = []
|
153 |
successful_prompts = []
|
154 |
failed_prompts = []
|
155 |
-
target_images = 10
|
|
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
|
|
160 |
|
161 |
-
#
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
# Prepare output text
|
176 |
-
text = f"Original Prompt: {prompt}\n\
|
|
|
|
|
|
|
|
|
177 |
for i, p in enumerate(successful_prompts, 1):
|
178 |
text += f"\n{i}. {p}"
|
179 |
|
180 |
if failed_prompts:
|
181 |
-
text +=
|
182 |
for i, p in enumerate(failed_prompts, 1):
|
183 |
text += f"\n{i}. {p}"
|
184 |
|
|
|
152 |
images = []
|
153 |
successful_prompts = []
|
154 |
failed_prompts = []
|
155 |
+
target_images = 10
|
156 |
+
max_attempts_per_image = 3 # Maksimal retry per gambar individual
|
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 |
+
# Ambil prompt dari batch, atau generate baru jika habis
|
170 |
+
if i + attempts >= len(optimized_prompts):
|
171 |
+
optimized_prompts.extend(generate_multiple_prompts(prompt, system_prompt))
|
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:
|
177 |
+
images.append(img)
|
178 |
+
successful_prompts.append(used_prompt)
|
179 |
+
success = True
|
180 |
+
else:
|
181 |
+
failed_prompts.append(used_prompt)
|
182 |
+
attempts += 1
|
183 |
+
except Exception as e:
|
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 |
|
191 |
# Prepare output text
|
192 |
+
text = f"Original Prompt: {prompt}\n\n"
|
193 |
+
text += f"Successfully Generated: {len(images)} images\n"
|
194 |
+
text += f"Failed Attempts: {len(failed_prompts)}\n\n"
|
195 |
+
|
196 |
+
text += "Successful Prompts:\n"
|
197 |
for i, p in enumerate(successful_prompts, 1):
|
198 |
text += f"\n{i}. {p}"
|
199 |
|
200 |
if failed_prompts:
|
201 |
+
text += "\n\nFailed Prompts:\n"
|
202 |
for i, p in enumerate(failed_prompts, 1):
|
203 |
text += f"\n{i}. {p}"
|
204 |
|