fantaxy commited on
Commit
35ec840
1 Parent(s): b3c7b3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +524 -196
app.py CHANGED
@@ -1,209 +1,537 @@
1
- #!/usr/bin/env python
2
-
3
- import os
4
- import random
5
- import uuid
6
-
7
  import gradio as gr
8
- import numpy as np
 
 
 
 
9
  from PIL import Image
10
- import spaces
11
- import torch
12
- from diffusers import DiffusionPipeline
13
-
14
-
15
- MAX_SEED = np.iinfo(np.int32).max
16
- CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1") == "1"
17
- MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1536"))
18
- USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
19
- ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
20
-
21
- device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
22
-
23
- NUM_IMAGES_PER_PROMPT = 1
24
-
25
- if torch.cuda.is_available():
26
- pipe = DiffusionPipeline.from_pretrained(
27
- "playgroundai/playground-v2.5-1024px-aesthetic",
28
- torch_dtype=torch.float16,
29
- use_safetensors=True,
30
- add_watermarker=False,
31
- variant="fp16"
32
- )
33
- if ENABLE_CPU_OFFLOAD:
34
- pipe.enable_model_cpu_offload()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  else:
36
- pipe.to(device)
37
- print("Loaded on Device!")
38
-
39
- if USE_TORCH_COMPILE:
40
- pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
41
- print("Model Compiled!")
42
-
43
-
44
- def save_image(img):
45
- unique_name = str(uuid.uuid4()) + ".png"
46
- img.save(unique_name)
47
- return unique_name
48
-
49
-
50
- def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
51
- if randomize_seed:
52
- seed = random.randint(0, MAX_SEED)
53
- return seed
54
-
55
-
56
- @spaces.GPU(enable_queue=True)
57
- def generate(
58
- prompt: str,
59
- negative_prompt: str = "",
60
- use_negative_prompt: bool = False,
61
- seed: int = 0,
62
- width: int = 1024,
63
- height: int = 1024,
64
- guidance_scale: float = 3,
65
- randomize_seed: bool = False,
66
- use_resolution_binning: bool = True,
67
- progress=gr.Progress(track_tqdm=True),
68
- ):
69
- pipe.to(device)
70
- seed = int(randomize_seed_fn(seed, randomize_seed))
71
- generator = torch.Generator().manual_seed(seed)
72
-
73
- if not use_negative_prompt:
74
- negative_prompt = None # type: ignore
75
-
76
- images = pipe(
77
- prompt=prompt,
78
- negative_prompt=negative_prompt,
79
- width=width,
80
- height=height,
81
- guidance_scale=guidance_scale,
82
- num_inference_steps=25,
83
- generator=generator,
84
- num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
85
- use_resolution_binning=use_resolution_binning,
86
- output_type="pil",
87
- ).images
88
-
89
- image_paths = [save_image(img) for img in images]
90
- print(image_paths)
91
- return image_paths, seed
92
-
93
-
94
- examples = [
95
- "neon holography crystal cat",
96
- "a cat eating a piece of cheese",
97
- "an astronaut riding a horse in space",
98
- "a cartoon of a boy playing with a tiger",
99
- "a cute robot artist painting on an easel, concept art",
100
- "a close up of a woman wearing a transparent, prismatic, elaborate nemeses headdress, over the should pose, brown skin-tone"
101
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  css = """
104
- footer {
105
- visibility: hidden;
106
- }
107
- #result-gallery {
108
- height: 600px; /* 원하는 높이로 설정 */
109
- overflow-y: auto;
110
- }
111
  """
112
 
113
- with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
114
 
115
- gr.DuplicateButton(
116
- value="Duplicate Space for private use",
117
- elem_id="duplicate-button",
118
- visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
119
- )
120
- with gr.Group():
121
  with gr.Row():
122
- prompt = gr.Text(
123
- label="Prompt",
124
- show_label=False,
125
- max_lines=1,
126
- placeholder="Enter your prompt",
127
- container=False,
128
- )
129
- run_button = gr.Button("Run", scale=0)
130
- result = gr.Gallery(label="Result", columns=NUM_IMAGES_PER_PROMPT, show_label=False, elem_id="result-gallery")
131
- with gr.Accordion("Advanced options", open=False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  with gr.Row():
133
- use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
134
- negative_prompt = gr.Text(
135
- label="Negative prompt",
136
- max_lines=1,
137
- placeholder="Enter a negative prompt",
138
- visible=True,
139
- )
140
- seed = gr.Slider(
141
- label="Seed",
142
- minimum=0,
143
- maximum=MAX_SEED,
144
- step=1,
145
- value=0,
146
- )
147
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
148
- with gr.Row(visible=True):
149
- width = gr.Slider(
150
- label="Width",
151
- minimum=256,
152
- maximum=MAX_IMAGE_SIZE,
153
- step=32,
154
- value=1024,
155
- )
156
- height = gr.Slider(
157
- label="Height",
158
- minimum=256,
159
- maximum=MAX_IMAGE_SIZE,
160
- step=32,
161
- value=1024,
162
- )
163
  with gr.Row():
164
- guidance_scale = gr.Slider(
165
- label="Guidance Scale",
166
- minimum=0.1,
167
- maximum=20,
168
- step=0.1,
169
- value=3.0,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  )
171
 
172
- gr.Examples(
173
- examples=examples,
174
- inputs=prompt,
175
- outputs=[result, seed],
176
- fn=generate,
177
- cache_examples=CACHE_EXAMPLES,
178
- )
179
-
180
- use_negative_prompt.change(
181
- fn=lambda x: gr.update(visible=x),
182
- inputs=use_negative_prompt,
183
- outputs=negative_prompt,
184
- api_name=False,
185
- )
186
-
187
- gr.on(
188
- triggers=[
189
- prompt.submit,
190
- negative_prompt.submit,
191
- run_button.click,
192
- ],
193
- fn=generate,
194
- inputs=[
195
- prompt,
196
- negative_prompt,
197
- use_negative_prompt,
198
- seed,
199
- width,
200
- height,
201
- guidance_scale,
202
- randomize_seed,
203
- ],
204
- outputs=[result, seed],
205
- api_name="run",
206
- )
207
-
208
- if __name__ == "__main__":
209
- demo.queue(max_size=20).launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import requests
3
+ import io
4
+ import random
5
+ import os
6
+ import time
7
  from PIL import Image
8
+ import json
9
+
10
+ # Project by Nymbo
11
+
12
+ # Base API URL for Hugging Face inference
13
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
14
+ # Retrieve the API token from environment variables
15
+ API_TOKEN = os.getenv("HF_READ_TOKEN")
16
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
17
+ # Timeout for requests
18
+ timeout = 100
19
+
20
+ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
21
+ # Debug log to indicate function start
22
+ print("Starting query function...")
23
+ # Print the parameters for debugging purposes
24
+ print(f"Prompt: {prompt}")
25
+ print(f"Model: {model}")
26
+ print(f"Custom LoRA: {custom_lora}")
27
+ print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")
28
+
29
+ # Check if the prompt is empty or None
30
+ if prompt == "" or prompt is None:
31
+ print("Prompt is empty or None. Exiting query function.") # Debug log
32
+ return None
33
+
34
+ # Generate a unique key for tracking the generation process
35
+ key = random.randint(0, 999)
36
+ print(f"Generated key: {key}") # Debug log
37
+
38
+ # Randomly select an API token from available options to distribute the load
39
+ 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")])
40
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
41
+ print(f"Selected API token: {API_TOKEN}") # Debug log
42
+
43
+ # Enhance the prompt with additional details for better quality
44
+ prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
45
+ print(f'Generation {key}: {prompt}') # Debug log
46
+
47
+ # Set the API URL based on the selected model or custom LoRA
48
+ if custom_lora.strip() != "":
49
+ API_URL = f"https://api-inference.huggingface.co/models/{custom_lora.strip()}"
50
  else:
51
+ if model == 'Stable Diffusion XL':
52
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
53
+ if model == 'FLUX.1 [Dev]':
54
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
55
+ if model == 'FLUX.1 [Schnell]':
56
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
57
+ if model == 'Flux Logo Design':
58
+ API_URL = "https://api-inference.huggingface.co/models/Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design"
59
+ prompt = f"wablogo, logo, Minimalist, {prompt}"
60
+ if model == 'Flux Uncensored':
61
+ API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
62
+ if model == 'Flux Uncensored V2':
63
+ API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-Uncensored-V2"
64
+ if model == 'Flux Tarot Cards':
65
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Ton618-Tarot-Cards-Flux-LoRA"
66
+ prompt = f"Tarot card, {prompt}"
67
+ if model == 'Pixel Art Sprites':
68
+ API_URL = "https://api-inference.huggingface.co/models/sWizad/pokemon-trainer-sprites-pixelart-flux"
69
+ prompt = f"a pixel image, {prompt}"
70
+ if model == '3D Sketchfab':
71
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-3D-Sketchfab-Flux-LoRA"
72
+ prompt = f"3D Sketchfab, {prompt}"
73
+ if model == 'Retro Comic Flux':
74
+ API_URL = "https://api-inference.huggingface.co/models/renderartist/retrocomicflux"
75
+ prompt = f"c0m1c, comic book panel, {prompt}"
76
+ if model == 'Caricature':
77
+ API_URL = "https://api-inference.huggingface.co/models/TheAwakenOne/caricature"
78
+ prompt = f"CCTUR3, {prompt}"
79
+ if model == 'Huggieverse':
80
+ API_URL = "https://api-inference.huggingface.co/models/Chunte/flux-lora-Huggieverse"
81
+ prompt = f"HGGRE, {prompt}"
82
+ if model == 'Propaganda Poster':
83
+ API_URL = "https://api-inference.huggingface.co/models/AlekseyCalvin/Propaganda_Poster_Schnell_by_doctor_diffusion"
84
+ prompt = f"propaganda poster, {prompt}"
85
+ if model == 'Flux Game Assets V2':
86
+ API_URL = "https://api-inference.huggingface.co/models/gokaygokay/Flux-Game-Assets-LoRA-v2"
87
+ prompt = f"wbgmsst, white background, {prompt}"
88
+ if model == 'SoftPasty Flux':
89
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/softpasty-flux-dev"
90
+ prompt = f"araminta_illus illustration style, {prompt}"
91
+ if model == 'Flux Stickers':
92
+ API_URL = "https://api-inference.huggingface.co/models/diabolic6045/Flux_Sticker_Lora"
93
+ prompt = f"5t1cker 5ty1e, {prompt}"
94
+ if model == 'Flux Animex V2':
95
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animex-v2-LoRA"
96
+ prompt = f"Animex, {prompt}"
97
+ if model == 'Flux Animeo V1':
98
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animeo-v1-LoRA"
99
+ prompt = f"Animeo, {prompt}"
100
+ if model == 'Movie Board':
101
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux.1-Dev-Movie-Boards-LoRA"
102
+ prompt = f"movieboard, {prompt}"
103
+ if model == 'Purple Dreamy':
104
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Purple-Dreamy-Flux-LoRA"
105
+ prompt = f"Purple Dreamy, {prompt}"
106
+ if model == 'PS1 Style Flux':
107
+ API_URL = "https://api-inference.huggingface.co/models/veryVANYA/ps1-style-flux"
108
+ prompt = f"ps1 game screenshot, {prompt}"
109
+ if model == 'Softserve Anime':
110
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/softserve_anime"
111
+ prompt = f"sftsrv style illustration, {prompt}"
112
+ if model == 'Flux Tarot v1':
113
+ API_URL = "https://api-inference.huggingface.co/models/multimodalart/flux-tarot-v1"
114
+ prompt = f"in the style of TOK a trtcrd tarot style, {prompt}"
115
+ if model == 'Half Illustration':
116
+ API_URL = "https://api-inference.huggingface.co/models/davisbro/half_illustration"
117
+ prompt = f"in the style of TOK, {prompt}"
118
+ if model == 'OpenDalle v1.1':
119
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
120
+ if model == 'Flux Ghibsky Illustration':
121
+ API_URL = "https://api-inference.huggingface.co/models/aleksa-codes/flux-ghibsky-illustration"
122
+ prompt = f"GHIBSKY style, {prompt}"
123
+ if model == 'Flux Koda':
124
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/flux-koda"
125
+ prompt = f"flmft style, {prompt}"
126
+ if model == 'Soviet Diffusion XL':
127
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/soviet-diffusion-xl"
128
+ prompt = f"soviet poster, {prompt}"
129
+ if model == 'Flux Realism LoRA':
130
+ API_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
131
+ if model == 'Frosting Lane Flux':
132
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/frosting_lane_flux"
133
+ prompt = f"frstingln illustration, {prompt}"
134
+ if model == 'Phantasma Anime':
135
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/phantasma-anime"
136
+ if model == 'Boreal':
137
+ API_URL = "https://api-inference.huggingface.co/models/kudzueye/Boreal"
138
+ prompt = f"photo, {prompt}"
139
+ if model == 'How2Draw':
140
+ API_URL = "https://api-inference.huggingface.co/models/glif/how2draw"
141
+ prompt = f"How2Draw, {prompt}"
142
+ if model == 'Flux AestheticAnime':
143
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-AestheticAnime"
144
+ if model == 'Fashion Hut Modeling LoRA':
145
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA"
146
+ prompt = f"Modeling of, {prompt}"
147
+ if model == 'Flux SyntheticAnime':
148
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-SyntheticAnime"
149
+ prompt = f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}"
150
+ if model == 'Flux Midjourney Anime':
151
+ API_URL = "https://api-inference.huggingface.co/models/brushpenbob/flux-midjourney-anime"
152
+ prompt = f"egmid, {prompt}"
153
+ if model == 'Coloring Book Generator':
154
+ API_URL = "https://api-inference.huggingface.co/models/robert123231/coloringbookgenerator"
155
+ if model == 'Collage Flux':
156
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-Collage-Dim-Flux-LoRA"
157
+ prompt = f"collage, {prompt}"
158
+ if model == 'Flux Product Ad Backdrop':
159
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Product-Ad-Backdrop"
160
+ prompt = f"Product Ad, {prompt}"
161
+ if model == 'Product Design':
162
+ API_URL = "https://api-inference.huggingface.co/models/multimodalart/product-design"
163
+ prompt = f"product designed by prdsgn, {prompt}"
164
+ if model == '90s Anime Art':
165
+ API_URL = "https://api-inference.huggingface.co/models/glif/90s-anime-art"
166
+ if model == 'Brain Melt Acid Art':
167
+ API_URL = "https://api-inference.huggingface.co/models/glif/Brain-Melt-Acid-Art"
168
+ prompt = f"maximalism, in an acid surrealism style, {prompt}"
169
+ if model == 'Lustly Flux Uncensored v1':
170
+ API_URL = "https://api-inference.huggingface.co/models/lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1"
171
+ if model == 'NSFW Master Flux':
172
+ API_URL = "https://api-inference.huggingface.co/models/Keltezaa/NSFW_MASTER_FLUX"
173
+ prompt = f"NSFW, {prompt}"
174
+ if model == 'Flux Outfit Generator':
175
+ API_URL = "https://api-inference.huggingface.co/models/tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator"
176
+ if model == 'Midjourney':
177
+ API_URL = "https://api-inference.huggingface.co/models/Jovie/Midjourney"
178
+ if model == 'DreamPhotoGASM':
179
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/DreamPhotoGASM"
180
+ if model == 'Flux Super Realism LoRA':
181
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Super-Realism-LoRA"
182
+ if model == 'Stable Diffusion 2-1':
183
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1-base"
184
+ if model == 'Stable Diffusion 3.5 Large':
185
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
186
+ if model == 'Stable Diffusion 3.5 Large Turbo':
187
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large-turbo"
188
+ if model == 'Stable Diffusion 3 Medium':
189
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
190
+ prompt = f"A, {prompt}"
191
+ if model == 'Duchaiten Real3D NSFW XL':
192
+ API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/duchaiten-real3d-nsfw-xl"
193
+ if model == 'Pixel Art XL':
194
+ API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
195
+ prompt = f"pixel art, {prompt}"
196
+ if model == 'Character Design':
197
+ API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/character-design"
198
+ prompt = f"Character Design, {prompt}"
199
+ if model == 'Sketched Out Manga':
200
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/sketchedoutmanga"
201
+ prompt = f"daiton, {prompt}"
202
+ if model == 'Archfey Anime':
203
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/archfey_anime"
204
+ if model == 'Lofi Cuties':
205
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/lofi-cuties"
206
+ if model == 'YiffyMix':
207
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/YiffyMix"
208
+ if model == 'Analog Madness Realistic v7':
209
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/AnalogMadness-realistic-model-v7"
210
+ if model == 'Selfie Photography':
211
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl"
212
+ prompt = f"instagram model, discord profile picture, {prompt}"
213
+ if model == 'Filmgrain':
214
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl"
215
+ prompt = f"Film Grain, FilmGrainAF, {prompt}"
216
+ if model == 'Leonardo AI Style Illustration':
217
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/Leonardo_Ai_Style_Illustration"
218
+ prompt = f"leonardo style, illustration, vector art, {prompt}"
219
+ if model == 'Cyborg Style XL':
220
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/cyborg_style_xl"
221
+ prompt = f"cyborg style, {prompt}"
222
+ if model == 'Little Tinies':
223
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/littletinies"
224
+ if model == 'NSFW XL':
225
+ API_URL = "https://api-inference.huggingface.co/models/Dremmar/nsfw-xl"
226
+ if model == 'Analog Redmond':
227
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/analogredmond"
228
+ prompt = f"timeless style, {prompt}"
229
+ if model == 'Pixel Art Redmond':
230
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/PixelArtRedmond"
231
+ prompt = f"Pixel Art, {prompt}"
232
+ if model == 'Ascii Art':
233
+ API_URL = "https://api-inference.huggingface.co/models/CiroN2022/ascii-art"
234
+ prompt = f"ascii art, {prompt}"
235
+ if model == 'Analog':
236
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/Analog"
237
+ if model == 'Maple Syrup':
238
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/MapleSyrup"
239
+ if model == 'Perfect Lewd Fantasy':
240
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/perfectLewdFantasy_v1.01"
241
+ if model == 'AbsoluteReality 1.8.1':
242
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/AbsoluteReality_v1.8.1"
243
+ if model == 'Disney':
244
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/disney_style_xl"
245
+ prompt = f"Disney style, {prompt}"
246
+ if model == 'Redmond SDXL':
247
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/LogoRedmond-LogoLoraForSDXL-V2"
248
+ if model == 'epiCPhotoGasm':
249
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/epiCPhotoGasm"
250
+ print(f"API URL set to: {API_URL}") # Debug log
251
+
252
+ # Define the payload for the request
253
+ payload = {
254
+ "inputs": prompt,
255
+ "is_negative": is_negative, # Whether to use a negative prompt
256
+ "steps": steps, # Number of sampling steps
257
+ "cfg_scale": cfg_scale, # Scale for controlling adherence to prompt
258
+ "seed": seed if seed != -1 else random.randint(1, 1000000000), # Random seed for reproducibility
259
+ "strength": strength, # How strongly the model should transform the image
260
+ "parameters": {
261
+ "width": width, # Width of the generated image
262
+ "height": height # Height of the generated image
263
+ }
264
+ }
265
+ print(f"Payload: {json.dumps(payload, indent=2)}") # Debug log
266
+
267
+ # Make a request to the API to generate the image
268
+ try:
269
+ response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
270
+ print(f"Response status code: {response.status_code}") # Debug log
271
+ except requests.exceptions.RequestException as e:
272
+ # Log any request exceptions and raise an error for the user
273
+ print(f"Request failed: {e}") # Debug log
274
+ raise gr.Error(f"Request failed: {e}")
275
 
276
+ # Check if the response status is not successful
277
+ if response.status_code != 200:
278
+ print(f"Error: Failed to retrieve image. Response status: {response.status_code}") # Debug log
279
+ print(f"Response content: {response.text}") # Debug log
280
+ if response.status_code == 400:
281
+ raise gr.Error(f"{response.status_code}: Bad Request - There might be an issue with the input parameters.")
282
+ elif response.status_code == 401:
283
+ raise gr.Error(f"{response.status_code}: Unauthorized - Please check your API token.")
284
+ elif response.status_code == 403:
285
+ raise gr.Error(f"{response.status_code}: Forbidden - You do not have permission to access this model.")
286
+ elif response.status_code == 404:
287
+ raise gr.Error(f"{response.status_code}: Not Found - The requested model could not be found.")
288
+ elif response.status_code == 503:
289
+ raise gr.Error(f"{response.status_code}: The model is being loaded. Please try again later.")
290
+ else:
291
+ raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
292
+
293
+ try:
294
+ # Attempt to read the image from the response content
295
+ image_bytes = response.content
296
+ image = Image.open(io.BytesIO(image_bytes))
297
+ print(f'Generation {key} completed! ({prompt})') # Debug log
298
+ return image
299
+ except Exception as e:
300
+ # Handle any errors that occur when opening the image
301
+ print(f"Error while trying to open image: {e}") # Debug log
302
+ return None
303
+
304
+ # Custom CSS to hide the footer in the interface
305
  css = """
306
+ * {}
307
+ footer {visibility: hidden !important;}
 
 
 
 
 
308
  """
309
 
310
+ print("Initializing Gradio interface...") # Debug log
311
 
312
+ # Define the Gradio interface
313
+ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
314
+ # Tab for basic settings
315
+ with gr.Tab("Basic Settings"):
 
 
316
  with gr.Row():
317
+ with gr.Column(elem_id="prompt-container"):
318
+ with gr.Row():
319
+ # Textbox for user to input the prompt
320
+ text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
321
+ with gr.Row():
322
+ # Textbox for custom LoRA input
323
+ custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
324
+ with gr.Row():
325
+ # Accordion for selecting the model
326
+ with gr.Accordion("Featured Models", open=True):
327
+ # Textbox for searching models
328
+ model_search = gr.Textbox(label="Filter Models", placeholder="Search for a featured model...", lines=1, elem_id="model-search-input")
329
+ models_list = (
330
+ "3D Sketchfab",
331
+ "90s Anime Art",
332
+ "AbsoluteReality 1.8.1",
333
+ "Analog",
334
+ "Analog Madness Realistic v7",
335
+ "Analog Redmond",
336
+ "Archfey Anime",
337
+ "Ascii Art",
338
+ "Brain Melt Acid Art",
339
+ "Boreal",
340
+ "Caricature",
341
+ "Collage Flux",
342
+ "Character Design",
343
+ "Coloring Book Generator",
344
+ "Cyborg Style XL",
345
+ "Disney",
346
+ "DreamPhotoGASM",
347
+ "Duchaiten Real3D NSFW XL",
348
+ "EpiCPhotoGasm",
349
+ "Fashion Hut Modeling LoRA",
350
+ "Filmgrain",
351
+ "FLUX.1 [Dev]",
352
+ "FLUX.1 [Schnell]",
353
+ "Flux Realism LoRA",
354
+ "Flux Super Realism LoRA",
355
+ "Flux Uncensored",
356
+ "Flux Uncensored V2",
357
+ "Flux Game Assets V2",
358
+ "Flux Ghibsky Illustration",
359
+ "Flux Animex V2",
360
+ "Flux Animeo V1",
361
+ "Flux AestheticAnime",
362
+ "Flux SyntheticAnime",
363
+ "Flux Stickers",
364
+ "Flux Koda",
365
+ "Flux Tarot v1",
366
+ "Flux Tarot Cards",
367
+ "Flux Midjourney Anime",
368
+ "Flux Logo Design",
369
+ "Flux Product Ad Backdrop",
370
+ "Flux Outfit Generator",
371
+ "Frosting Lane Flux",
372
+ "Half Illustration",
373
+ "How2Draw",
374
+ "Huggieverse",
375
+ "Leonardo AI Style Illustration",
376
+ "Little Tinies",
377
+ "Lofi Cuties",
378
+ "Lustly Flux Uncensored v1",
379
+ "Maple Syrup",
380
+ "Midjourney",
381
+ "Movie Board",
382
+ "NSFW Master Flux",
383
+ "NSFW XL",
384
+ "OpenDalle v1.1",
385
+ "Perfect Lewd Fantasy",
386
+ "Pixel Art Redmond",
387
+ "Pixel Art XL",
388
+ "Pixel Art Sprites",
389
+ "Product Design",
390
+ "Propaganda Poster",
391
+ "Purple Dreamy",
392
+ "Phantasma Anime",
393
+ "PS1 Style Flux",
394
+ "Redmond SDXL",
395
+ "Retro Comic Flux",
396
+ "Softserve Anime",
397
+ "SoftPasty Flux",
398
+ "Soviet Diffusion XL",
399
+ "Sketched Out Manga",
400
+ "Selfie Photography",
401
+ "Stable Diffusion 2-1",
402
+ "Stable Diffusion XL",
403
+ "Stable Diffusion 3 Medium",
404
+ "Stable Diffusion 3.5 Large",
405
+ "Stable Diffusion 3.5 Large Turbo",
406
+ "YiffyMix",
407
+ )
408
+
409
+ # Radio buttons to select the desired model
410
+ model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio")
411
+
412
+ # Filtering models based on search input
413
+ def filter_models(search_term):
414
+ filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
415
+ return gr.update(choices=filtered_models)
416
+
417
+ # Update model list when search box is used
418
+ model_search.change(filter_models, inputs=model_search, outputs=model)
419
+
420
+ # Tab for advanced settings
421
+ with gr.Tab("Advanced Settings"):
422
  with gr.Row():
423
+ # Textbox for specifying elements to exclude from the image
424
+ 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")
425
+ with gr.Row():
426
+ # Slider for selecting the image width
427
+ width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
428
+ # Slider for selecting the image height
429
+ height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
430
+ with gr.Row():
431
+ # Slider for setting the number of sampling steps
432
+ steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
433
+ with gr.Row():
434
+ # Slider for adjusting the CFG scale (guidance scale)
435
+ cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
436
+ with gr.Row():
437
+ # Slider for adjusting the transformation strength
438
+ strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
439
+ with gr.Row():
440
+ # Slider for setting the seed for reproducibility
441
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
 
 
 
 
 
 
 
 
 
 
442
  with gr.Row():
443
+ # Radio buttons for selecting the sampling method
444
+ method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
445
+
446
+ # Tab for image editing options
447
+ with gr.Tab("Image Editor"):
448
+ # Function to simulate a delay for processing
449
+ def sleep(im):
450
+ print("Sleeping for 5 seconds...") # Debug log
451
+ time.sleep(5)
452
+ return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
453
+
454
+ # Function to return the composite image
455
+ def predict(im):
456
+ print("Predicting composite image...") # Debug log
457
+ return im["composite"]
458
+
459
+ with gr.Blocks() as demo:
460
+ with gr.Row():
461
+ # Image editor component for user adjustments
462
+ im = gr.ImageEditor(
463
+ type="numpy",
464
+ crop_size="1:1", # Set crop size to a square aspect ratio
465
+ )
466
+
467
+ # Tab to provide information to the user
468
+ with gr.Tab("Information"):
469
+ with gr.Row():
470
+ # Display a sample prompt for guidance
471
+ gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
472
+
473
+ # Accordion displaying featured models
474
+ with gr.Accordion("Featured Models (WiP)", open=False):
475
+ gr.HTML(
476
+ """
477
+ <p><a href="https://huggingface.co/models?inference=warm&pipeline_tag=text-to-image&sort=trending">See all available models</a></p>
478
+ <table style="width:100%; text-align:center; margin:auto;">
479
+ <tr>
480
+ <th>Model Name</th>
481
+ <th>Typography</th>
482
+ <th>Notes</th>
483
+ </tr>
484
+ <tr>
485
+ <td>FLUX.1 Dev</td>
486
+ <td>✅</td>
487
+ <td></td>
488
+ </tr>
489
+ <tr>
490
+ <td>FLUX.1 Schnell</td>
491
+ <td>✅</td>
492
+ <td></td>
493
+ </tr>
494
+ <tr>
495
+ <td>Stable Diffusion 3.5 Large</td>
496
+ <td>✅</td>
497
+ <td></td>
498
+ </tr>
499
+ </table>
500
+ """
501
+ )
502
+
503
+ # Accordion providing an overview of advanced settings
504
+ with gr.Accordion("Advanced Settings Overview", open=False):
505
+ gr.Markdown(
506
+ """
507
+ ## Negative Prompt
508
+ ###### 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.
509
+ ## Width & Height
510
+ ###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
511
+ ## Sampling Steps
512
+ ###### 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.
513
+ ## CFG Scale
514
+ ###### 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".
515
+ ## Sampling Method
516
+ ###### 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.
517
+ ## Strength
518
+ ###### 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.
519
+ ## Seed
520
+ ###### 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.
521
+ ### 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!
522
+ """
523
  )
524
 
525
+ # Row containing the 'Run' button to trigger the image generation
526
+ with gr.Row():
527
+ text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
528
+ # Row for displaying the generated image output
529
+ with gr.Row():
530
+ image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
531
+
532
+ # Set up button click event to call the query function
533
+ text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
534
+
535
+ print("Launching Gradio interface...") # Debug log
536
+ # Launch the Gradio interface without showing the API or sharing externally
537
+ dalle.launch(show_api=False, share=False)