Update app.py
Browse files
app.py
CHANGED
@@ -149,29 +149,36 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
|
|
149 |
if token and accountId:
|
150 |
setAccount(token, accountId)
|
151 |
|
152 |
-
# Generate multiple optimized prompts
|
153 |
-
optimized_prompts = generate_multiple_prompts(prompt, system_prompt)
|
154 |
-
|
155 |
-
# Generate images for each prompt
|
156 |
images = []
|
157 |
successful_prompts = []
|
158 |
failed_prompts = []
|
|
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
# Prepare output text
|
169 |
-
text = f"Original Prompt: {prompt}\n\nSuccessful Generations:\n"
|
170 |
for i, p in enumerate(successful_prompts, 1):
|
171 |
text += f"\n{i}. {p}"
|
172 |
|
173 |
if failed_prompts:
|
174 |
-
text += "\n\nFailed
|
175 |
for i, p in enumerate(failed_prompts, 1):
|
176 |
text += f"\n{i}. {p}"
|
177 |
|
|
|
149 |
if token and accountId:
|
150 |
setAccount(token, accountId)
|
151 |
|
|
|
|
|
|
|
|
|
152 |
images = []
|
153 |
successful_prompts = []
|
154 |
failed_prompts = []
|
155 |
+
target_images = 10 # Jumlah gambar yang diinginkan
|
156 |
|
157 |
+
while len(images) < target_images:
|
158 |
+
# Generate batch of prompts
|
159 |
+
optimized_prompts = generate_multiple_prompts(prompt, system_prompt)
|
160 |
+
|
161 |
+
# Try each prompt until we get enough images
|
162 |
+
for opt_prompt in optimized_prompts:
|
163 |
+
if len(images) >= target_images:
|
164 |
+
break
|
165 |
+
|
166 |
+
img, used_prompt = generate_image_with_fallback(opt_prompt)
|
167 |
+
if img is not None:
|
168 |
+
images.append(img)
|
169 |
+
successful_prompts.append(used_prompt)
|
170 |
+
else:
|
171 |
+
failed_prompts.append(used_prompt)
|
172 |
+
# Jika gagal, generate prompt baru dan coba lagi
|
173 |
+
continue
|
174 |
|
175 |
# Prepare output text
|
176 |
+
text = f"Original Prompt: {prompt}\n\nSuccessful Generations ({len(successful_prompts)}):\n"
|
177 |
for i, p in enumerate(successful_prompts, 1):
|
178 |
text += f"\n{i}. {p}"
|
179 |
|
180 |
if failed_prompts:
|
181 |
+
text += f"\n\nFailed Attempts ({len(failed_prompts)}):\n"
|
182 |
for i, p in enumerate(failed_prompts, 1):
|
183 |
text += f"\n{i}. {p}"
|
184 |
|