| 160 | |
| 161 | # --- Gradio Interface Logic --- |
| 162 | def generate_image_interface( |
| 163 | original_prompt, enable_recap, height, width, |
| 164 | num_inference_steps, guidance_scale, seed_input |
| 165 | ): |
| 166 | if not original_prompt or not original_prompt.strip(): |
| 167 | raise gr.Error("Prompt cannot be empty!") |
| 168 | |
| 169 | try: |
| 170 | actual_seed = int(seed_input) if seed_input and seed_input > 0 else random.randint(1, 2**32 - 1) |
| 171 | |
| 172 | image, final_prompt = generator.generate( |
| 173 | prompt=original_prompt, |
| 174 | enable_recap=enable_recap, |
| 175 | height=int(height), |
| 176 | width=int(width), |
| 177 | num_inference_steps=int(num_inference_steps), |
| 178 | guidance_scale=float(guidance_scale), |
| 179 | seed=actual_seed |
| 180 | ) |
| 181 | |
| 182 | status_log = f"Seed: {actual_seed} | Generation complete." |
| 183 | return image, final_prompt, status_log |
| 184 | |
| 185 | except Exception as e: |
| 186 | raise gr.Error(f"An error occurred: {e}") |
| 187 | |
| 188 | |
| 189 | # --- Gradio UI Definition --- |