llamameta commited on
Commit
d0a6377
1 Parent(s): b825beb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -156,28 +156,18 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
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
 
@@ -189,7 +179,7 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
189
  failed_prompts.append(used_prompt)
190
  attempts += 1
191
  except Exception as e:
192
- failed_prompts.append(f"{current_prompt} (Error: {str(e)})")
193
  attempts += 1
194
 
195
  if not success:
 
156
  max_attempts_per_image = 3
157
  used_prompts = set() # Untuk tracking prompt yang sudah digunakan
158
 
 
 
 
 
 
 
159
  for i in range(target_images):
160
  attempts = 0
161
  success = False
162
 
163
  while attempts < max_attempts_per_image and not success:
164
  try:
165
+ # Generate prompt baru yang unik
166
+ current_prompt = generate_text(prompt, system_prompt)
167
+ while current_prompt in used_prompts:
168
+ current_prompt = generate_text(prompt, system_prompt)
 
 
169
 
170
+ used_prompts.add(current_prompt)
 
 
171
 
172
  img, used_prompt = generate_image_with_fallback(current_prompt)
173
 
 
179
  failed_prompts.append(used_prompt)
180
  attempts += 1
181
  except Exception as e:
182
+ failed_prompts.append(f"Error: {str(e)}")
183
  attempts += 1
184
 
185
  if not success: