File size: 26,394 Bytes
c7278d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
import gradio as gr
import requests
import io
import random
import os
import time
from PIL import Image
import json

# Project by Nymbo

# Base API URL for Hugging Face inference
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
# Retrieve the API token from environment variables
API_TOKEN = os.getenv("HF_READ_TOKEN")
headers = {"Authorization": f"Bearer {API_TOKEN}"}
# Timeout for requests
timeout = 100

def query(prompt, model, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
    # Debug log to indicate function start
    print("Starting query function...")
    # Print the parameters for debugging purposes
    print(f"Prompt: {prompt}")
    print(f"Model: {model}")
    print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")

    # Check if the prompt is empty or None
    if prompt == "" or prompt is None:
        print("Prompt is empty or None. Exiting query function.")  # Debug log
        return None

    # Generate a unique key for tracking the generation process
    key = random.randint(0, 999)
    print(f"Generated key: {key}")  # Debug log

    # Randomly select an API token from available options to distribute the load
    API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN"), os.getenv("HF_READ_TOKEN_2"), os.getenv("HF_READ_TOKEN_3"), os.getenv("HF_READ_TOKEN_4"), os.getenv("HF_READ_TOKEN_5")])
    headers = {"Authorization": f"Bearer {API_TOKEN}"}
    print(f"Selected API token: {API_TOKEN}")  # Debug log

    # Enhance the prompt with additional details for better quality
    prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
    print(f'Generation {key}: {prompt}')  # Debug log

    # Set the API URL based on the selected model
    
#    if model == 'X':
#        API_URL = "https://api-inference.huggingface.co/models/X"
#        prompt = f"X, {prompt}"

    if model == 'Stable Diffusion XL':
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
    if model == 'FLUX.1 [Dev]':
        API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
    if model == 'FLUX.1 [Schnell]':
        API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
    if model == 'PS1 Style Flux':
        API_URL = "https://api-inference.huggingface.co/models/veryVANYA/ps1-style-flux"
        prompt = f"ps1 game screenshot, {prompt}"
    if model == 'Softserve Anime':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/softserve_anime"
        prompt = f"sftsrv style illustration, {prompt}"
    if model == 'Flux Tarot v1':
        API_URL = "https://api-inference.huggingface.co/models/multimodalart/flux-tarot-v1"
        prompt = f"in the style of TOK a trtcrd tarot style, {prompt}"
    if model == 'Half Illustration':
        API_URL = "https://api-inference.huggingface.co/models/davisbro/half_illustration"
        prompt = f"in the style of TOK, {prompt}"
    if model == 'OpenDalle v1.1':
        API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
    if model == 'Flux Ghibsky Illustration':
        API_URL = "https://api-inference.huggingface.co/models/aleksa-codes/flux-ghibsky-illustration"
        prompt = f"GHIBSKY style, {prompt}"
    if model == 'Flux Koda':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/flux-koda"
        prompt = f"flmft style, {prompt}"
    if model == 'Soviet Diffusion XL':
        API_URL = "https://api-inference.huggingface.co/models/openskyml/soviet-diffusion-xl"
        prompt = f"soviet poster, {prompt}"
    if model == 'Flux Realism LoRA':
        API_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
    if model == 'Frosting Lane Flux':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/frosting_lane_flux"
        prompt = f"frstingln illustration, {prompt}"
    if model == 'Phantasma Anime':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/phantasma-anime"
    if model == 'Boreal':
        API_URL = "https://api-inference.huggingface.co/models/kudzueye/Boreal"
        prompt = f"photo, {prompt}"
    if model == 'How2Draw':
        API_URL = "https://api-inference.huggingface.co/models/glif/how2draw"
        prompt = f"How2Draw, {prompt}"
    if model == 'Flux AestheticAnime':
        API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-AestheticAnime"
    if model == 'Fashion Hut Modeling LoRA':
        API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA"
        prompt = f"Modeling of, {prompt}"
    if model == 'Flux SyntheticAnime':
        API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-SyntheticAnime"
        prompt = f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}"
    if model == 'Flux Midjourney Anime':
        API_URL = "https://api-inference.huggingface.co/models/brushpenbob/flux-midjourney-anime"
        prompt = f"egmid, {prompt}"
    if model == 'Coloring Book Generator':
        API_URL = "https://api-inference.huggingface.co/models/robert123231/coloringbookgenerator"
    if model == 'Castor Collage Flux LoRA':
        API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-Collage-Dim-Flux-LoRA"
        prompt = f"collage, {prompt}"
    if model == 'Flux Product Ad Backdrop':
        API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Product-Ad-Backdrop"
        prompt = f"Product Ad, {prompt}"
    if model == 'Product Design':
        API_URL = "https://api-inference.huggingface.co/models/multimodalart/product-design"
        prompt = f"product designed by prdsgn, {prompt}"
    if model == '90s Anime Art':
        API_URL = "https://api-inference.huggingface.co/models/glif/90s-anime-art"
    if model == 'Brain Melt Acid Art':
        API_URL = "https://api-inference.huggingface.co/models/glif/Brain-Melt-Acid-Art"
        prompt = f"maximalism, in an acid surrealism style, {prompt}"
    if model == 'Lustly Flux Uncensored v1':
        API_URL = "https://api-inference.huggingface.co/models/lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1"
    if model == 'NSFW Master Flux':
        API_URL = "https://api-inference.huggingface.co/models/Keltezaa/NSFW_MASTER_FLUX"
        prompt = f"NSFW, {prompt}"
    if model == 'Flux Outfit Generator':
        API_URL = "https://api-inference.huggingface.co/models/tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator"
    if model == 'Midjourney':
        API_URL = "https://api-inference.huggingface.co/models/Jovie/Midjourney"
    if model == 'DreamPhotoGASM':
        API_URL = "https://api-inference.huggingface.co/models/Yntec/DreamPhotoGASM"
    if model == 'Flux Super Realism LoRA':
        API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Super-Realism-LoRA"
    if model == 'Stable Diffusion 2-1':
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1-base"
    if model == 'Stable Diffusion 3.5 Large':
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
    if model == 'Stable Diffusion 3.5 Large Turbo':
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large-turbo"
    if model == 'Stable Diffusion 3 Medium':
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
        prompt = f"A, {prompt}"
    if model == 'Duchaiten Real3D NSFW XL':
        API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/duchaiten-real3d-nsfw-xl"
    if model == 'Pixel Art XL':
        API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
        prompt = f"pixel art, {prompt}"
    if model == 'Character Design':
        API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/character-design"
        prompt = f"Character Design, {prompt}"
    if model == 'Sketched Out Manga':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/sketchedoutmanga"
        prompt = f"daiton, {prompt}"
    if model == 'Archfey Anime':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/archfey_anime"
    if model == 'Lofi Cuties':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/lofi-cuties"
    if model == 'YiffyMix':
        API_URL = "https://api-inference.huggingface.co/models/Yntec/YiffyMix"
    if model == 'Analog Madness Realistic v7':
        API_URL = "https://api-inference.huggingface.co/models/digiplay/AnalogMadness-realistic-model-v7"
    if model == 'Selfie Photography':
        API_URL = "https://api-inference.huggingface.co/models/artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl"
        prompt = f"instagram model, discord profile picture, {prompt}"
    if model == 'Filmgrain':
        API_URL = "https://api-inference.huggingface.co/models/artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl"
        prompt = f"Film Grain, FilmGrainAF, {prompt}"
    if model == 'Leonardo AI Style Illustration':
        API_URL = "https://api-inference.huggingface.co/models/goofyai/Leonardo_Ai_Style_Illustration"
        prompt = f"leonardo style, illustration, vector art, {prompt}"
    if model == 'Cyborg Style XL':
        API_URL = "https://api-inference.huggingface.co/models/goofyai/cyborg_style_xl"
        prompt = f"cyborg style, {prompt}"
    if model == 'Little Tinies':
        API_URL = "https://api-inference.huggingface.co/models/alvdansen/littletinies"
    if model == 'NSFW XL':
        API_URL = "https://api-inference.huggingface.co/models/Dremmar/nsfw-xl"
    if model == 'Analog Redmond':
        API_URL = "https://api-inference.huggingface.co/models/artificialguybr/analogredmond"
        prompt = f"timeless style, {prompt}"
    if model == 'Pixel Art Redmond':
        API_URL = "https://api-inference.huggingface.co/models/artificialguybr/PixelArtRedmond"
        prompt = f"Pixel Art, {prompt}"
    if model == 'Ascii Art':
        API_URL = "https://api-inference.huggingface.co/models/CiroN2022/ascii-art"
        prompt = f"ascii art, {prompt}"
    if model == 'Analog':
        API_URL = "https://api-inference.huggingface.co/models/Yntec/Analog"
    if model == 'Maple Syrup':
        API_URL = "https://api-inference.huggingface.co/models/Yntec/MapleSyrup"
    if model == 'Perfect Lewd Fantasy':
        API_URL = "https://api-inference.huggingface.co/models/digiplay/perfectLewdFantasy_v1.01"
    if model == 'AbsoluteReality 1.8.1':
        API_URL = "https://api-inference.huggingface.co/models/digiplay/AbsoluteReality_v1.8.1"
    if model == 'Disney':
        API_URL = "https://api-inference.huggingface.co/models/goofyai/disney_style_xl"
        prompt = f"Disney style, {prompt}"
    if model == 'Redmond SDXL':
        API_URL = "https://api-inference.huggingface.co/models/artificialguybr/LogoRedmond-LogoLoraForSDXL-V2"
    if model == 'epiCPhotoGasm':
        API_URL = "https://api-inference.huggingface.co/models/Yntec/epiCPhotoGasm"
    print(f"API URL set to: {API_URL}")  # Debug log

    # Define the payload for the request
    payload = {
        "inputs": prompt,
        "is_negative": is_negative,  # Whether to use a negative prompt
        "steps": steps,  # Number of sampling steps
        "cfg_scale": cfg_scale,  # Scale for controlling adherence to prompt
        "seed": seed if seed != -1 else random.randint(1, 1000000000),  # Random seed for reproducibility
        "strength": strength,  # How strongly the model should transform the image
        "parameters": {
            "width": width,  # Width of the generated image
            "height": height  # Height of the generated image
        }
    }
    print(f"Payload: {json.dumps(payload, indent=2)}")  # Debug log

    # Make a request to the API to generate the image
    try:
        response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
        print(f"Response status code: {response.status_code}")  # Debug log
    except requests.exceptions.RequestException as e:
        # Log any request exceptions and raise an error for the user
        print(f"Request failed: {e}")  # Debug log
        raise gr.Error(f"Request failed: {e}")

    # Check if the response status is not successful
    if response.status_code != 200:
        print(f"Error: Failed to retrieve image. Response status: {response.status_code}")  # Debug log
        print(f"Response content: {response.text}")  # Debug log
        if response.status_code == 400:
            raise gr.Error(f"{response.status_code}: Bad Request - There might be an issue with the input parameters.")
        elif response.status_code == 401:
            raise gr.Error(f"{response.status_code}: Unauthorized - Please check your API token.")
        elif response.status_code == 403:
            raise gr.Error(f"{response.status_code}: Forbidden - You do not have permission to access this model.")
        elif response.status_code == 404:
            raise gr.Error(f"{response.status_code}: Not Found - The requested model could not be found.")
        elif response.status_code == 503:
            raise gr.Error(f"{response.status_code}: The model is being loaded. Please try again later.")
        else:
            raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
    
    try:
        # Attempt to read the image from the response content
        image_bytes = response.content
        image = Image.open(io.BytesIO(image_bytes))
        print(f'Generation {key} completed! ({prompt})')  # Debug log
        return image
    except Exception as e:
        # Handle any errors that occur when opening the image
        print(f"Error while trying to open image: {e}")  # Debug log
        return None

# Custom CSS to hide the footer in the interface
css = """
* {}
footer {visibility: hidden !important;}
"""

print("Initializing Gradio interface...")  # Debug log

# Define the Gradio interface
with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
    # Tab for basic settings
    with gr.Tab("Basic Settings"):
        with gr.Row():
            with gr.Column(elem_id="prompt-container"):
                with gr.Row():
                    # Textbox for user to input the prompt
                    text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
                with gr.Row():
                    # Accordion for selecting the model
                    with gr.Accordion("Model Selection", open=True):
                        # Textbox for searching models
                        model_search = gr.Textbox(label="Search Models", placeholder="Search for a model...", lines=1, elem_id="model-search-input")
                        models_list = (
                            "90s Anime Art",
                            "AbsoluteReality 1.8.1",
                            "Analog",
                            "Analog Madness Realistic v7",
                            "Analog Redmond",
                            "Archfey Anime",
                            "Ascii Art",
                            "Brain Melt Acid Art",
                            "Boreal",
                            "Castor Collage Flux LoRA",
                            "Character Design",
                            "Coloring Book Generator",
                            "Cyborg Style XL",
                            "Disney",
                            "DreamPhotoGASM",
                            "Duchaiten Real3D NSFW XL",
                            "EpiCPhotoGasm",
                            "Fashion Hut Modeling LoRA",
                            "Filmgrain",
                            "FLUX.1 [Dev]",
                            "FLUX.1 [Schnell]",
                            "Flux Realism LoRA",
                            "Flux Super Realism LoRA",
                            "Flux Ghibsky Illustration",
                            "Flux AestheticAnime",
                            "Flux SyntheticAnime",
                            "Flux Koda",
                            "Flux Tarot v1",
                            "Flux Midjourney Anime",
                            "Flux Product Ad Backdrop",
                            "Flux Outfit Generator",
                            "Frosting Lane Flux",
                            "Half Illustration",
                            "How2Draw",
                            "Leonardo AI Style Illustration",
                            "Little Tinies",
                            "Lofi Cuties",
                            "Lustly Flux Uncensored v1",
                            "Maple Syrup",
                            "Midjourney",
                            "NSFW Master Flux",
                            "NSFW XL",
                            "OpenDalle v1.1",
                            "Perfect Lewd Fantasy",
                            "Pixel Art Redmond",
                            "Pixel Art XL",
                            "Product Design",
                            "Phantasma Anime",
                            "PS1 Style Flux",
                            "Redmond SDXL",
                            "Softserve Anime",
                            "Soviet Diffusion XL",
                            "Sketched Out Manga",
                            "Selfie Photography",
                            "Stable Diffusion 2-1"
                            "Stable Diffusion XL",
                            "Stable Diffusion 3 Medium",
                            "Stable Diffusion 3.5 Large",
                            "Stable Diffusion 3.5 Large Turbo",
                            "YiffyMix",
                        )

                        # Radio buttons to select the desired model
                        model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio")

                        # Filtering models based on search input
                        def filter_models(search_term):
                            filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
                            return gr.update(choices=filtered_models)

                        # Update model list when search box is used
                        model_search.change(filter_models, inputs=model_search, outputs=model)

    # Tab for advanced settings
    with gr.Tab("Advanced Settings"):
        with gr.Row():
            # Textbox for specifying elements to exclude from the image
            negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
        with gr.Row():
            # Slider for selecting the image width
            width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
            # Slider for selecting the image height
            height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
        with gr.Row():
            # Slider for setting the number of sampling steps
            steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
        with gr.Row():
            # Slider for adjusting the CFG scale (guidance scale)
            cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
        with gr.Row():
            # Slider for adjusting the transformation strength
            strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
        with gr.Row():
            # Slider for setting the seed for reproducibility
            seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
        with gr.Row():
            # Radio buttons for selecting the sampling method
            method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])

    # Tab for image editing options
    with gr.Tab("Image Editor"):
        # Function to simulate a delay for processing
        def sleep(im):
            print("Sleeping for 5 seconds...")  # Debug log
            time.sleep(5)
            return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]

        # Function to return the composite image
        def predict(im):
            print("Predicting composite image...")  # Debug log
            return im["composite"]

        with gr.Blocks() as demo:
            with gr.Row():
                # Image editor component for user adjustments
                im = gr.ImageEditor(
                    type="numpy",
                    crop_size="1:1",  # Set crop size to a square aspect ratio
                )

    # Tab to provide information to the user
    with gr.Tab("Information"):
        with gr.Row():
            # Display a sample prompt for guidance
            gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
            
        # Accordion displaying featured models
        with gr.Accordion("Featured Models (WiP)", open=False):
            gr.HTML(
                """
            <table style="width:100%; text-align:center; margin:auto;">
                <tr>
                    <th>Model Name</th>
                    <th>Typography</th>
                    <th>Notes</th>
                </tr>
                <tr>
                    <td>FLUX.1 Dev</td>
                    <td>✅</td>
                    <td></td>
                </tr>
                <tr>
                    <td>FLUX.1 Schnell</td>
                    <td>✅</td>
                    <td></td>
                </tr>
                <tr>
                    <td>Stable Diffusion 3.5 Large</td>
                    <td>✅</td>
                    <td></td>
                </tr>
            </table>

            """
            )

        # Accordion providing an overview of advanced settings
        with gr.Accordion("Advanced Settings Overview", open=False):
            gr.Markdown(
                """
            ## Negative Prompt
            ###### This box is for telling the AI what you don't want in your images. Think of it as a way to avoid certain elements. For instance, if you don't want blurry images or extra limbs showing up, this is where you'd mention it.

            ## Width & Height
            ###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.

            ## Sampling Steps
            ###### Think of this like the number of brushstrokes in a painting. A higher number can give you a more detailed picture, but it also takes a bit longer. Generally, a middle-ground number like 35 is a good balance between quality and speed.

            ## CFG Scale
            ###### CFG stands for "Control Free Guidance." The scale adjusts how closely the AI follows your prompt. A lower number makes the AI more creative and free-flowing, while a higher number makes it stick closely to what you asked for. If you want the AI to take fewer artistic liberties, slide this towards a higher number. Just think "Control Freak Gauge".
            
            ## Sampling Method
            ###### This is the technique the AI uses to create your image. Each option is a different approach, like choosing between pencils, markers, or paint. You don't need to worry too much about this; the default setting is usually the best choice for most users.

            ## Strength
            ###### This setting is a bit like the 'intensity' knob. It determines how much the AI modifies the base image it starts with. If you're looking to make subtle changes, keep this low. For more drastic transformations, turn it up.

            ## Seed
            ###### You can think of the seed as a 'recipe' for creating an image. If you find a seed that gives you a result you love, you can use it again to create a similar image. If you leave it at -1, the AI will generate a new seed every time.

            ### Remember, these settings are all about giving you control over the image generation process. Feel free to experiment and see what each one does. And if you're ever in doubt, the default settings are a great place to start. Happy creating!
            """
            )

        # Accordion explaining possible error codes
        with gr.Accordion("Error Codes and What They Mean", open=False):
            gr.Markdown(
                """
            ## Error Codes:
            #### 500: Error Fetching Model
            ###### This is a temporary error usually caused by a model experiencing high demand, or it is being updated. Try again in a few minutes.

            #### 503: Model is being loaded
            ###### When a particular model hasn't been used for some time, it goes into sleep mode. Error 503 means that the model is being loaded and will be ready within a minute.
            """
            )

    # Row containing the 'Run' button to trigger the image generation
    with gr.Row():
        text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
    # Row for displaying the generated image output
    with gr.Row():
        image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
        
    # Set up button click event to call the query function
    text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)

print("Launching Gradio interface...")  # Debug log
# Launch the Gradio interface without showing the API or sharing externally
dalle.launch(show_api=False, share=False)