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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/stabilityai/stable-diffusion-xl-base-1.0"
|
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, 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"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")
|
27 |
+
|
28 |
+
# Check if the prompt is empty or None
|
29 |
+
if prompt == "" or prompt is None:
|
30 |
+
print("Prompt is empty or None. Exiting query function.") # Debug log
|
31 |
+
return None
|
32 |
+
|
33 |
+
# Generate a unique key for tracking the generation process
|
34 |
+
key = random.randint(0, 999)
|
35 |
+
print(f"Generated key: {key}") # Debug log
|
36 |
+
|
37 |
+
# Randomly select an API token from available options to distribute the load
|
38 |
+
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")])
|
39 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
40 |
+
print(f"Selected API token: {API_TOKEN}") # Debug log
|
41 |
+
|
42 |
+
# Enhance the prompt with additional details for better quality
|
43 |
+
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
44 |
+
print(f'Generation {key}: {prompt}') # Debug log
|
45 |
+
|
46 |
+
# Set the API URL based on the selected model
|
47 |
+
|
48 |
+
# if model == 'X':
|
49 |
+
# API_URL = "https://api-inference.huggingface.co/models/X"
|
50 |
+
# prompt = f"X, {prompt}"
|
51 |
+
|
52 |
+
if model == 'Stable Diffusion XL':
|
53 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
54 |
+
if model == 'FLUX.1 [Dev]':
|
55 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
56 |
+
if model == 'FLUX.1 [Schnell]':
|
57 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
|
58 |
+
if model == 'PS1 Style Flux':
|
59 |
+
API_URL = "https://api-inference.huggingface.co/models/veryVANYA/ps1-style-flux"
|
60 |
+
prompt = f"ps1 game screenshot, {prompt}"
|
61 |
+
if model == 'Softserve Anime':
|
62 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/softserve_anime"
|
63 |
+
prompt = f"sftsrv style illustration, {prompt}"
|
64 |
+
if model == 'Flux Tarot v1':
|
65 |
+
API_URL = "https://api-inference.huggingface.co/models/multimodalart/flux-tarot-v1"
|
66 |
+
prompt = f"in the style of TOK a trtcrd tarot style, {prompt}"
|
67 |
+
if model == 'Half Illustration':
|
68 |
+
API_URL = "https://api-inference.huggingface.co/models/davisbro/half_illustration"
|
69 |
+
prompt = f"in the style of TOK, {prompt}"
|
70 |
+
if model == 'OpenDalle v1.1':
|
71 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
|
72 |
+
if model == 'Flux Ghibsky Illustration':
|
73 |
+
API_URL = "https://api-inference.huggingface.co/models/aleksa-codes/flux-ghibsky-illustration"
|
74 |
+
prompt = f"GHIBSKY style, {prompt}"
|
75 |
+
if model == 'Flux Koda':
|
76 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/flux-koda"
|
77 |
+
prompt = f"flmft style, {prompt}"
|
78 |
+
if model == 'Soviet Diffusion XL':
|
79 |
+
API_URL = "https://api-inference.huggingface.co/models/openskyml/soviet-diffusion-xl"
|
80 |
+
prompt = f"soviet poster, {prompt}"
|
81 |
+
if model == 'Flux Realism LoRA':
|
82 |
+
API_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
|
83 |
+
if model == 'Frosting Lane Flux':
|
84 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/frosting_lane_flux"
|
85 |
+
prompt = f"frstingln illustration, {prompt}"
|
86 |
+
if model == 'Phantasma Anime':
|
87 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/phantasma-anime"
|
88 |
+
if model == 'Boreal':
|
89 |
+
API_URL = "https://api-inference.huggingface.co/models/kudzueye/Boreal"
|
90 |
+
prompt = f"photo, {prompt}"
|
91 |
+
if model == 'How2Draw':
|
92 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/how2draw"
|
93 |
+
prompt = f"How2Draw, {prompt}"
|
94 |
+
if model == 'Flux AestheticAnime':
|
95 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-AestheticAnime"
|
96 |
+
if model == 'Fashion Hut Modeling LoRA':
|
97 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA"
|
98 |
+
prompt = f"Modeling of, {prompt}"
|
99 |
+
if model == 'Flux SyntheticAnime':
|
100 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-SyntheticAnime"
|
101 |
+
prompt = f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}"
|
102 |
+
if model == 'Flux Midjourney Anime':
|
103 |
+
API_URL = "https://api-inference.huggingface.co/models/brushpenbob/flux-midjourney-anime"
|
104 |
+
prompt = f"egmid, {prompt}"
|
105 |
+
if model == 'Coloring Book Generator':
|
106 |
+
API_URL = "https://api-inference.huggingface.co/models/robert123231/coloringbookgenerator"
|
107 |
+
if model == 'Castor Collage Flux LoRA':
|
108 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-Collage-Dim-Flux-LoRA"
|
109 |
+
prompt = f"collage, {prompt}"
|
110 |
+
if model == 'Flux Product Ad Backdrop':
|
111 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Product-Ad-Backdrop"
|
112 |
+
prompt = f"Product Ad, {prompt}"
|
113 |
+
if model == 'Product Design':
|
114 |
+
API_URL = "https://api-inference.huggingface.co/models/multimodalart/product-design"
|
115 |
+
prompt = f"product designed by prdsgn, {prompt}"
|
116 |
+
if model == '90s Anime Art':
|
117 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/90s-anime-art"
|
118 |
+
if model == 'Brain Melt Acid Art':
|
119 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/Brain-Melt-Acid-Art"
|
120 |
+
prompt = f"maximalism, in an acid surrealism style, {prompt}"
|
121 |
+
if model == 'Lustly Flux Uncensored v1':
|
122 |
+
API_URL = "https://api-inference.huggingface.co/models/lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1"
|
123 |
+
if model == 'NSFW Master Flux':
|
124 |
+
API_URL = "https://api-inference.huggingface.co/models/Keltezaa/NSFW_MASTER_FLUX"
|
125 |
+
prompt = f"NSFW, {prompt}"
|
126 |
+
if model == 'Flux Outfit Generator':
|
127 |
+
API_URL = "https://api-inference.huggingface.co/models/tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator"
|
128 |
+
if model == 'Midjourney':
|
129 |
+
API_URL = "https://api-inference.huggingface.co/models/Jovie/Midjourney"
|
130 |
+
if model == 'DreamPhotoGASM':
|
131 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/DreamPhotoGASM"
|
132 |
+
if model == 'Flux Super Realism LoRA':
|
133 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Super-Realism-LoRA"
|
134 |
+
if model == 'Stable Diffusion 2-1':
|
135 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1-base"
|
136 |
+
if model == 'Stable Diffusion 3.5 Large':
|
137 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
|
138 |
+
if model == 'Stable Diffusion 3.5 Large Turbo':
|
139 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large-turbo"
|
140 |
+
if model == 'Stable Diffusion 3 Medium':
|
141 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
|
142 |
+
prompt = f"A, {prompt}"
|
143 |
+
if model == 'Duchaiten Real3D NSFW XL':
|
144 |
+
API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/duchaiten-real3d-nsfw-xl"
|
145 |
+
if model == 'Pixel Art XL':
|
146 |
+
API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
|
147 |
+
prompt = f"pixel art, {prompt}"
|
148 |
+
if model == 'Character Design':
|
149 |
+
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/character-design"
|
150 |
+
prompt = f"Character Design, {prompt}"
|
151 |
+
if model == 'Sketched Out Manga':
|
152 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/sketchedoutmanga"
|
153 |
+
prompt = f"daiton, {prompt}"
|
154 |
+
if model == 'Archfey Anime':
|
155 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/archfey_anime"
|
156 |
+
if model == 'Lofi Cuties':
|
157 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/lofi-cuties"
|
158 |
+
if model == 'YiffyMix':
|
159 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/YiffyMix"
|
160 |
+
if model == 'Analog Madness Realistic v7':
|
161 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/AnalogMadness-realistic-model-v7"
|
162 |
+
if model == 'Selfie Photography':
|
163 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl"
|
164 |
+
prompt = f"instagram model, discord profile picture, {prompt}"
|
165 |
+
if model == 'Filmgrain':
|
166 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl"
|
167 |
+
prompt = f"Film Grain, FilmGrainAF, {prompt}"
|
168 |
+
if model == 'Leonardo AI Style Illustration':
|
169 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/Leonardo_Ai_Style_Illustration"
|
170 |
+
prompt = f"leonardo style, illustration, vector art, {prompt}"
|
171 |
+
if model == 'Cyborg Style XL':
|
172 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/cyborg_style_xl"
|
173 |
+
prompt = f"cyborg style, {prompt}"
|
174 |
+
if model == 'Little Tinies':
|
175 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/littletinies"
|
176 |
+
if model == 'NSFW XL':
|
177 |
+
API_URL = "https://api-inference.huggingface.co/models/Dremmar/nsfw-xl"
|
178 |
+
if model == 'Analog Redmond':
|
179 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/analogredmond"
|
180 |
+
prompt = f"timeless style, {prompt}"
|
181 |
+
if model == 'Pixel Art Redmond':
|
182 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/PixelArtRedmond"
|
183 |
+
prompt = f"Pixel Art, {prompt}"
|
184 |
+
if model == 'Ascii Art':
|
185 |
+
API_URL = "https://api-inference.huggingface.co/models/CiroN2022/ascii-art"
|
186 |
+
prompt = f"ascii art, {prompt}"
|
187 |
+
if model == 'Analog':
|
188 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/Analog"
|
189 |
+
if model == 'Maple Syrup':
|
190 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/MapleSyrup"
|
191 |
+
if model == 'Perfect Lewd Fantasy':
|
192 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/perfectLewdFantasy_v1.01"
|
193 |
+
if model == 'AbsoluteReality 1.8.1':
|
194 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/AbsoluteReality_v1.8.1"
|
195 |
+
if model == 'Disney':
|
196 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/disney_style_xl"
|
197 |
+
prompt = f"Disney style, {prompt}"
|
198 |
+
if model == 'Redmond SDXL':
|
199 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/LogoRedmond-LogoLoraForSDXL-V2"
|
200 |
+
if model == 'epiCPhotoGasm':
|
201 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/epiCPhotoGasm"
|
202 |
+
print(f"API URL set to: {API_URL}") # Debug log
|
203 |
+
|
204 |
+
# Define the payload for the request
|
205 |
+
payload = {
|
206 |
+
"inputs": prompt,
|
207 |
+
"is_negative": is_negative, # Whether to use a negative prompt
|
208 |
+
"steps": steps, # Number of sampling steps
|
209 |
+
"cfg_scale": cfg_scale, # Scale for controlling adherence to prompt
|
210 |
+
"seed": seed if seed != -1 else random.randint(1, 1000000000), # Random seed for reproducibility
|
211 |
+
"strength": strength, # How strongly the model should transform the image
|
212 |
+
"parameters": {
|
213 |
+
"width": width, # Width of the generated image
|
214 |
+
"height": height # Height of the generated image
|
215 |
+
}
|
216 |
+
}
|
217 |
+
print(f"Payload: {json.dumps(payload, indent=2)}") # Debug log
|
218 |
+
|
219 |
+
# Make a request to the API to generate the image
|
220 |
+
try:
|
221 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
222 |
+
print(f"Response status code: {response.status_code}") # Debug log
|
223 |
+
except requests.exceptions.RequestException as e:
|
224 |
+
# Log any request exceptions and raise an error for the user
|
225 |
+
print(f"Request failed: {e}") # Debug log
|
226 |
+
raise gr.Error(f"Request failed: {e}")
|
227 |
+
|
228 |
+
# Check if the response status is not successful
|
229 |
+
if response.status_code != 200:
|
230 |
+
print(f"Error: Failed to retrieve image. Response status: {response.status_code}") # Debug log
|
231 |
+
print(f"Response content: {response.text}") # Debug log
|
232 |
+
if response.status_code == 400:
|
233 |
+
raise gr.Error(f"{response.status_code}: Bad Request - There might be an issue with the input parameters.")
|
234 |
+
elif response.status_code == 401:
|
235 |
+
raise gr.Error(f"{response.status_code}: Unauthorized - Please check your API token.")
|
236 |
+
elif response.status_code == 403:
|
237 |
+
raise gr.Error(f"{response.status_code}: Forbidden - You do not have permission to access this model.")
|
238 |
+
elif response.status_code == 404:
|
239 |
+
raise gr.Error(f"{response.status_code}: Not Found - The requested model could not be found.")
|
240 |
+
elif response.status_code == 503:
|
241 |
+
raise gr.Error(f"{response.status_code}: The model is being loaded. Please try again later.")
|
242 |
+
else:
|
243 |
+
raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
|
244 |
+
|
245 |
+
try:
|
246 |
+
# Attempt to read the image from the response content
|
247 |
+
image_bytes = response.content
|
248 |
+
image = Image.open(io.BytesIO(image_bytes))
|
249 |
+
print(f'Generation {key} completed! ({prompt})') # Debug log
|
250 |
+
return image
|
251 |
+
except Exception as e:
|
252 |
+
# Handle any errors that occur when opening the image
|
253 |
+
print(f"Error while trying to open image: {e}") # Debug log
|
254 |
+
return None
|
255 |
+
|
256 |
+
# Custom CSS to hide the footer in the interface
|
257 |
+
css = """
|
258 |
+
* {}
|
259 |
+
footer {visibility: hidden !important;}
|
260 |
+
"""
|
261 |
+
|
262 |
+
print("Initializing Gradio interface...") # Debug log
|
263 |
+
|
264 |
+
# Define the Gradio interface
|
265 |
+
with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
266 |
+
# Tab for basic settings
|
267 |
+
with gr.Tab("Basic Settings"):
|
268 |
+
with gr.Row():
|
269 |
+
with gr.Column(elem_id="prompt-container"):
|
270 |
+
with gr.Row():
|
271 |
+
# Textbox for user to input the prompt
|
272 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
|
273 |
+
with gr.Row():
|
274 |
+
# Accordion for selecting the model
|
275 |
+
with gr.Accordion("Model Selection", open=True):
|
276 |
+
# Textbox for searching models
|
277 |
+
model_search = gr.Textbox(label="Search Models", placeholder="Search for a model...", lines=1, elem_id="model-search-input")
|
278 |
+
models_list = (
|
279 |
+
"90s Anime Art",
|
280 |
+
"AbsoluteReality 1.8.1",
|
281 |
+
"Analog",
|
282 |
+
"Analog Madness Realistic v7",
|
283 |
+
"Analog Redmond",
|
284 |
+
"Archfey Anime",
|
285 |
+
"Ascii Art",
|
286 |
+
"Brain Melt Acid Art",
|
287 |
+
"Boreal",
|
288 |
+
"Castor Collage Flux LoRA",
|
289 |
+
"Character Design",
|
290 |
+
"Coloring Book Generator",
|
291 |
+
"Cyborg Style XL",
|
292 |
+
"Disney",
|
293 |
+
"DreamPhotoGASM",
|
294 |
+
"Duchaiten Real3D NSFW XL",
|
295 |
+
"EpiCPhotoGasm",
|
296 |
+
"Fashion Hut Modeling LoRA",
|
297 |
+
"Filmgrain",
|
298 |
+
"FLUX.1 [Dev]",
|
299 |
+
"FLUX.1 [Schnell]",
|
300 |
+
"Flux Realism LoRA",
|
301 |
+
"Flux Super Realism LoRA",
|
302 |
+
"Flux Ghibsky Illustration",
|
303 |
+
"Flux AestheticAnime",
|
304 |
+
"Flux SyntheticAnime",
|
305 |
+
"Flux Koda",
|
306 |
+
"Flux Tarot v1",
|
307 |
+
"Flux Midjourney Anime",
|
308 |
+
"Flux Product Ad Backdrop",
|
309 |
+
"Flux Outfit Generator",
|
310 |
+
"Frosting Lane Flux",
|
311 |
+
"Half Illustration",
|
312 |
+
"How2Draw",
|
313 |
+
"Leonardo AI Style Illustration",
|
314 |
+
"Little Tinies",
|
315 |
+
"Lofi Cuties",
|
316 |
+
"Lustly Flux Uncensored v1",
|
317 |
+
"Maple Syrup",
|
318 |
+
"Midjourney",
|
319 |
+
"NSFW Master Flux",
|
320 |
+
"NSFW XL",
|
321 |
+
"OpenDalle v1.1",
|
322 |
+
"Perfect Lewd Fantasy",
|
323 |
+
"Pixel Art Redmond",
|
324 |
+
"Pixel Art XL",
|
325 |
+
"Product Design",
|
326 |
+
"Phantasma Anime",
|
327 |
+
"PS1 Style Flux",
|
328 |
+
"Redmond SDXL",
|
329 |
+
"Softserve Anime",
|
330 |
+
"Soviet Diffusion XL",
|
331 |
+
"Sketched Out Manga",
|
332 |
+
"Selfie Photography",
|
333 |
+
"Stable Diffusion 2-1"
|
334 |
+
"Stable Diffusion XL",
|
335 |
+
"Stable Diffusion 3 Medium",
|
336 |
+
"Stable Diffusion 3.5 Large",
|
337 |
+
"Stable Diffusion 3.5 Large Turbo",
|
338 |
+
"YiffyMix",
|
339 |
+
)
|
340 |
+
|
341 |
+
# Radio buttons to select the desired model
|
342 |
+
model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio")
|
343 |
+
|
344 |
+
# Filtering models based on search input
|
345 |
+
def filter_models(search_term):
|
346 |
+
filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
|
347 |
+
return gr.update(choices=filtered_models)
|
348 |
+
|
349 |
+
# Update model list when search box is used
|
350 |
+
model_search.change(filter_models, inputs=model_search, outputs=model)
|
351 |
+
|
352 |
+
# Tab for advanced settings
|
353 |
+
with gr.Tab("Advanced Settings"):
|
354 |
+
with gr.Row():
|
355 |
+
# Textbox for specifying elements to exclude from the image
|
356 |
+
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")
|
357 |
+
with gr.Row():
|
358 |
+
# Slider for selecting the image width
|
359 |
+
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
360 |
+
# Slider for selecting the image height
|
361 |
+
height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
|
362 |
+
with gr.Row():
|
363 |
+
# Slider for setting the number of sampling steps
|
364 |
+
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
|
365 |
+
with gr.Row():
|
366 |
+
# Slider for adjusting the CFG scale (guidance scale)
|
367 |
+
cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
|
368 |
+
with gr.Row():
|
369 |
+
# Slider for adjusting the transformation strength
|
370 |
+
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
371 |
+
with gr.Row():
|
372 |
+
# Slider for setting the seed for reproducibility
|
373 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
374 |
+
with gr.Row():
|
375 |
+
# Radio buttons for selecting the sampling method
|
376 |
+
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
377 |
+
|
378 |
+
# Tab for image editing options
|
379 |
+
with gr.Tab("Image Editor"):
|
380 |
+
# Function to simulate a delay for processing
|
381 |
+
def sleep(im):
|
382 |
+
print("Sleeping for 5 seconds...") # Debug log
|
383 |
+
time.sleep(5)
|
384 |
+
return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
|
385 |
+
|
386 |
+
# Function to return the composite image
|
387 |
+
def predict(im):
|
388 |
+
print("Predicting composite image...") # Debug log
|
389 |
+
return im["composite"]
|
390 |
+
|
391 |
+
with gr.Blocks() as demo:
|
392 |
+
with gr.Row():
|
393 |
+
# Image editor component for user adjustments
|
394 |
+
im = gr.ImageEditor(
|
395 |
+
type="numpy",
|
396 |
+
crop_size="1:1", # Set crop size to a square aspect ratio
|
397 |
+
)
|
398 |
+
|
399 |
+
# Tab to provide information to the user
|
400 |
+
with gr.Tab("Information"):
|
401 |
+
with gr.Row():
|
402 |
+
# Display a sample prompt for guidance
|
403 |
+
gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
|
404 |
+
|
405 |
+
# Accordion displaying featured models
|
406 |
+
with gr.Accordion("Featured Models (WiP)", open=False):
|
407 |
+
gr.HTML(
|
408 |
+
"""
|
409 |
+
<table style="width:100%; text-align:center; margin:auto;">
|
410 |
+
<tr>
|
411 |
+
<th>Model Name</th>
|
412 |
+
<th>Typography</th>
|
413 |
+
<th>Notes</th>
|
414 |
+
</tr>
|
415 |
+
<tr>
|
416 |
+
<td>FLUX.1 Dev</td>
|
417 |
+
<td>✅</td>
|
418 |
+
<td></td>
|
419 |
+
</tr>
|
420 |
+
<tr>
|
421 |
+
<td>FLUX.1 Schnell</td>
|
422 |
+
<td>✅</td>
|
423 |
+
<td></td>
|
424 |
+
</tr>
|
425 |
+
<tr>
|
426 |
+
<td>Stable Diffusion 3.5 Large</td>
|
427 |
+
<td>✅</td>
|
428 |
+
<td></td>
|
429 |
+
</tr>
|
430 |
+
</table>
|
431 |
+
|
432 |
+
"""
|
433 |
+
)
|
434 |
+
|
435 |
+
# Accordion providing an overview of advanced settings
|
436 |
+
with gr.Accordion("Advanced Settings Overview", open=False):
|
437 |
+
gr.Markdown(
|
438 |
+
"""
|
439 |
+
## Negative Prompt
|
440 |
+
###### 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.
|
441 |
+
|
442 |
+
## Width & Height
|
443 |
+
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
|
444 |
+
|
445 |
+
## Sampling Steps
|
446 |
+
###### 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.
|
447 |
+
|
448 |
+
## CFG Scale
|
449 |
+
###### 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".
|
450 |
+
|
451 |
+
## Sampling Method
|
452 |
+
###### 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.
|
453 |
+
|
454 |
+
## Strength
|
455 |
+
###### 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.
|
456 |
+
|
457 |
+
## Seed
|
458 |
+
###### 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.
|
459 |
+
|
460 |
+
### 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!
|
461 |
+
"""
|
462 |
+
)
|
463 |
+
|
464 |
+
# Accordion explaining possible error codes
|
465 |
+
with gr.Accordion("Error Codes and What They Mean", open=False):
|
466 |
+
gr.Markdown(
|
467 |
+
"""
|
468 |
+
## Error Codes:
|
469 |
+
#### 500: Error Fetching Model
|
470 |
+
###### This is a temporary error usually caused by a model experiencing high demand, or it is being updated. Try again in a few minutes.
|
471 |
+
|
472 |
+
#### 503: Model is being loaded
|
473 |
+
###### 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.
|
474 |
+
"""
|
475 |
+
)
|
476 |
+
|
477 |
+
# Row containing the 'Run' button to trigger the image generation
|
478 |
+
with gr.Row():
|
479 |
+
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
480 |
+
# Row for displaying the generated image output
|
481 |
+
with gr.Row():
|
482 |
+
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
483 |
+
|
484 |
+
# Set up button click event to call the query function
|
485 |
+
text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
|
486 |
+
|
487 |
+
print("Launching Gradio interface...") # Debug log
|
488 |
+
# Launch the Gradio interface without showing the API or sharing externally
|
489 |
+
dalle.launch(show_api=False, share=False)
|