llamameta commited on
Commit
0c57ea5
1 Parent(s): e646899

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
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 # 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
 
 
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