Update app.py
Browse files
app.py
CHANGED
@@ -4,58 +4,28 @@ import io
|
|
4 |
import random
|
5 |
import os
|
6 |
import time
|
7 |
-
import json
|
8 |
from PIL import Image
|
|
|
9 |
|
10 |
# Project by Nymbo
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
|
|
|
|
14 |
# Timeout for requests
|
15 |
timeout = 100
|
16 |
|
17 |
-
|
18 |
-
def query_hf_inference(prompt, model_path, headers, payload, timeout):
|
19 |
-
"""Handler for Hugging Face Inference API requests"""
|
20 |
-
api_url = f"https://api-inference.huggingface.co/models/{model_path}"
|
21 |
-
print(f"Making request to HF Inference API: {api_url}")
|
22 |
-
return requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
23 |
-
|
24 |
-
def query_fal_ai(prompt, model_path, headers, payload, timeout):
|
25 |
-
"""Handler for Fal AI API requests"""
|
26 |
-
api_url = f"https://live.fal.ai/hugging-face/{model_path}"
|
27 |
-
print(f"Making request to Fal AI: {api_url}")
|
28 |
-
return requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
29 |
-
|
30 |
-
def query_nebius(prompt, model_path, headers, payload, timeout):
|
31 |
-
"""Handler for Nebius API requests"""
|
32 |
-
api_url = f"https://router.huggingface.co/nebius/v1/text-to-image/{model_path}"
|
33 |
-
print(f"Making request to Nebius: {api_url}")
|
34 |
-
return requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
35 |
-
|
36 |
-
def query_replicate(prompt, model_path, headers, payload, timeout):
|
37 |
-
"""Handler for Replicate API requests"""
|
38 |
-
api_url = f"https://router.huggingface.co/replicate/v1/text-to-image/{model_path}"
|
39 |
-
print(f"Making request to Replicate: {api_url}")
|
40 |
-
return requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
41 |
-
|
42 |
-
def query_together(prompt, model_path, headers, payload, timeout):
|
43 |
-
"""Handler for Together API requests"""
|
44 |
-
api_url = f"https://router.huggingface.co/together/v1/text-to-image/{model_path}"
|
45 |
-
print(f"Making request to Together: {api_url}")
|
46 |
-
return requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
47 |
-
|
48 |
-
# Main query function
|
49 |
-
def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras",
|
50 |
-
seed=-1, strength=0.7, width=1024, height=1024, custom_api_key="", provider="hf-inference"):
|
51 |
# Debug log to indicate function start
|
52 |
print("Starting query function...")
|
53 |
# Print the parameters for debugging purposes
|
54 |
print(f"Prompt: {prompt}")
|
55 |
print(f"Model: {model}")
|
56 |
print(f"Custom LoRA: {custom_lora}")
|
57 |
-
print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")
|
58 |
print(f"Provider: {provider}")
|
|
|
59 |
print(f"Custom API Key provided: {bool(custom_api_key.strip())}") # Log whether a custom key was provided without printing the key
|
60 |
|
61 |
# Check if the prompt is empty or None
|
@@ -72,16 +42,14 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
72 |
print("USING CUSTOM API KEY: BYOK token provided by user is being used for authentication")
|
73 |
API_TOKEN = custom_api_key.strip()
|
74 |
else:
|
75 |
-
if provider
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
API_TOKEN = HF_TOKEN
|
84 |
-
print("USING DEFAULT HF TOKEN: Environment variable HF_TOKEN is being used for authentication")
|
85 |
|
86 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
87 |
|
@@ -89,200 +57,315 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
89 |
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
90 |
print(f'Generation {key}: {prompt}') # Debug log
|
91 |
|
92 |
-
# Set the
|
93 |
if custom_lora.strip() != "":
|
94 |
-
|
95 |
else:
|
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 |
# Define the payload for the request
|
288 |
payload = {
|
@@ -299,21 +382,46 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
299 |
}
|
300 |
print(f"Payload: {json.dumps(payload, indent=2)}") # Debug log
|
301 |
|
302 |
-
#
|
303 |
-
|
304 |
-
|
305 |
-
"
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
try:
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
print(f"Response status code: {response.status_code}") # Debug log
|
318 |
except requests.exceptions.RequestException as e:
|
319 |
# Log any request exceptions and raise an error for the user
|
@@ -338,8 +446,21 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
338 |
raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
|
339 |
|
340 |
try:
|
341 |
-
#
|
342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
image = Image.open(io.BytesIO(image_bytes))
|
344 |
print(f'Generation {key} completed! ({prompt})') # Debug log
|
345 |
return image
|
@@ -495,26 +616,58 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
495 |
# Tab for advanced settings
|
496 |
with gr.Tab("Advanced Settings"):
|
497 |
with gr.Row():
|
498 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
provider_radio = gr.Radio(
|
500 |
-
choices=
|
501 |
value="hf-inference",
|
502 |
label="Inference Provider",
|
503 |
-
info="Select
|
|
|
504 |
)
|
|
|
505 |
with gr.Row():
|
506 |
# BYOK (Bring Your Own Key) textbox
|
507 |
byok_textbox = gr.Textbox(
|
508 |
value="",
|
509 |
label="BYOK (Bring Your Own Key)",
|
510 |
-
info="Enter a custom API key here.
|
511 |
placeholder="Enter your API token",
|
512 |
type="password", # Hide the API key for security
|
513 |
elem_id="byok-input"
|
514 |
)
|
515 |
-
|
516 |
-
|
517 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
with gr.Row():
|
519 |
# Slider for selecting the image width
|
520 |
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
@@ -536,23 +689,6 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
536 |
# Radio buttons for selecting the sampling method
|
537 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
538 |
|
539 |
-
# Function to validate provider selection
|
540 |
-
def validate_provider(api_key, provider):
|
541 |
-
# If custom key is provided, any provider can be used
|
542 |
-
if api_key.strip():
|
543 |
-
return gr.update(value=provider, interactive=True)
|
544 |
-
# If no custom key is provided, only HF Inference is allowed
|
545 |
-
elif provider != "hf-inference":
|
546 |
-
return gr.update(value="hf-inference", interactive=True)
|
547 |
-
return gr.update(value=provider, interactive=True)
|
548 |
-
|
549 |
-
# Connect the BYOK textbox to validate provider selection
|
550 |
-
byok_textbox.change(
|
551 |
-
fn=validate_provider,
|
552 |
-
inputs=[byok_textbox, provider_radio],
|
553 |
-
outputs=provider_radio
|
554 |
-
)
|
555 |
-
|
556 |
# Tab for image editing options
|
557 |
with gr.Tab("Image Editor"):
|
558 |
# Function to simulate a delay for processing
|
@@ -610,46 +746,24 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
610 |
"""
|
611 |
)
|
612 |
|
613 |
-
# Accordion providing an overview of providers
|
614 |
-
with gr.Accordion("Providers Information", open=False):
|
615 |
-
gr.Markdown(
|
616 |
-
"""
|
617 |
-
## Inference Providers
|
618 |
-
|
619 |
-
This application supports multiple inference providers for image generation:
|
620 |
-
|
621 |
-
### HF Inference
|
622 |
-
###### The default Hugging Face Inference API. This is a serverless solution that allows you to run model inference on Hugging Face's infrastructure. Free to use with limitations.
|
623 |
-
|
624 |
-
### Fal AI
|
625 |
-
###### Fal AI provides optimized inference for image generation models. May offer better performance for certain model types.
|
626 |
-
|
627 |
-
### Nebius
|
628 |
-
###### Nebius AI is a technology company specializing in AI-centric cloud platforms, offering scalable GPU clusters for inference.
|
629 |
-
|
630 |
-
### Replicate
|
631 |
-
###### Replicate's API makes it easy to run machine learning models in the cloud with a simple API.
|
632 |
-
|
633 |
-
### Together
|
634 |
-
###### Together AI offers high-performance inference for various AI models.
|
635 |
-
|
636 |
-
When no custom API key is provided, only HF Inference can be used. For other providers, you must bring your own API key.
|
637 |
-
"""
|
638 |
-
)
|
639 |
-
|
640 |
# Accordion providing an overview of advanced settings
|
641 |
with gr.Accordion("Advanced Settings Overview", open=False):
|
642 |
gr.Markdown(
|
643 |
"""
|
644 |
-
## Inference Provider
|
645 |
-
###### Select which provider to use for image generation. Each provider has different performance characteristics and model availability.
|
646 |
-
|
647 |
-
## BYOK (Bring Your Own Key)
|
648 |
-
###### This allows you to use your own API key instead of the default keys. Enter your key here for direct access to models using your account's permissions and rate limits.
|
649 |
-
|
650 |
## Negative Prompt
|
651 |
###### 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.
|
652 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
## Width & Height
|
654 |
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
|
655 |
|
@@ -679,8 +793,8 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
679 |
with gr.Row():
|
680 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
681 |
|
682 |
-
# Set up button click event to call the query function with
|
683 |
-
text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height,
|
684 |
|
685 |
print("Launching Gradio interface...") # Debug log
|
686 |
# Launch the Gradio interface without showing the API or sharing externally
|
|
|
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, provider="hf-inference", custom_api_key=""):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"Provider: {provider}")
|
28 |
+
print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")
|
29 |
print(f"Custom API Key provided: {bool(custom_api_key.strip())}") # Log whether a custom key was provided without printing the key
|
30 |
|
31 |
# Check if the prompt is empty or None
|
|
|
42 |
print("USING CUSTOM API KEY: BYOK token provided by user is being used for authentication")
|
43 |
API_TOKEN = custom_api_key.strip()
|
44 |
else:
|
45 |
+
# If no custom key, check if provider is "hf-inference"
|
46 |
+
if provider != "hf-inference":
|
47 |
+
print(f"ERROR: Custom API key is required for {provider} provider")
|
48 |
+
raise gr.Error(f"A custom API key is required when using the {provider} provider. Please enter your key in the BYOK field.")
|
49 |
+
|
50 |
+
# For hf-inference, randomly select an API token from available options to distribute the load
|
51 |
+
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")])
|
52 |
+
print("USING DEFAULT API KEY: Random environment variable token is being used for authentication")
|
|
|
|
|
53 |
|
54 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
55 |
|
|
|
57 |
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
58 |
print(f'Generation {key}: {prompt}') # Debug log
|
59 |
|
60 |
+
# Set the API URL based on the selected model or custom LoRA
|
61 |
if custom_lora.strip() != "":
|
62 |
+
API_URL = f"https://api-inference.huggingface.co/models/{custom_lora.strip()}"
|
63 |
else:
|
64 |
+
if model == 'Stable Diffusion XL':
|
65 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
66 |
+
if model == 'FLUX.1 [Dev]':
|
67 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
68 |
+
if model == 'FLUX.1 [Schnell]':
|
69 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
|
70 |
+
if model == 'HiDream-I1-Full':
|
71 |
+
API_URL = "https://api-inference.huggingface.co/models/HiDream-ai/HiDream-I1-Full"
|
72 |
+
if model == 'HiDream-I1-Dev':
|
73 |
+
API_URL = "https://api-inference.huggingface.co/models/HiDream-ai/HiDream-I1-Dev"
|
74 |
+
if model == 'HiDream-I1-Fast':
|
75 |
+
API_URL = "https://api-inference.huggingface.co/models/HiDream-ai/HiDream-I1-Fast"
|
76 |
+
if model == 'Animagine 4.0':
|
77 |
+
API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-4.0"
|
78 |
+
prompt = f"masterpiece, high score, great score, absurdres, {prompt}"
|
79 |
+
if model == 'Flux Icon Kit':
|
80 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Icon-Kit-LoRA"
|
81 |
+
prompt = f"Icon Kit, {prompt}"
|
82 |
+
if model == 'Pixel Background':
|
83 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Pixel-Background-LoRA"
|
84 |
+
prompt = f"Pixel Background, {prompt}"
|
85 |
+
if model == 'Meme XD':
|
86 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Meme-Xd-LoRA"
|
87 |
+
prompt = f"meme, {prompt}"
|
88 |
+
if model == 'Chill Guy':
|
89 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Chill-Guy-Zone"
|
90 |
+
prompt = f"chill guy, {prompt}"
|
91 |
+
if model == 'Pepe':
|
92 |
+
API_URL = "https://api-inference.huggingface.co/models/openfree/pepe"
|
93 |
+
prompt = f"pepe, {prompt}"
|
94 |
+
if model == 'NSFWmodel':
|
95 |
+
API_URL = "https://api-inference.huggingface.co/models/lexa862/NSFWmodel"
|
96 |
+
prompt = f"nude, {prompt}"
|
97 |
+
if model == 'Claude Art':
|
98 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Claude-Art"
|
99 |
+
prompt = f"claude art, {prompt}"
|
100 |
+
if model == 'Open Genmoji':
|
101 |
+
API_URL = "https://api-inference.huggingface.co/models/EvanZhouDev/open-genmoji"
|
102 |
+
prompt = f"emoji, {prompt}"
|
103 |
+
if model == 'EBook Creative Cover':
|
104 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/EBook-Creative-Cover-Flux-LoRA"
|
105 |
+
prompt = f"EBook Cover, {prompt}"
|
106 |
+
if model == 'Flux Logo Design 2':
|
107 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Logo-Design-Flux-LoRA"
|
108 |
+
prompt = f"Logo Design, {prompt}"
|
109 |
+
if model == 'Isometric 3D':
|
110 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Isometric-3D-LoRA"
|
111 |
+
prompt = f"Isometric 3D, {prompt}"
|
112 |
+
if model == 'Flux Condensation':
|
113 |
+
API_URL = "https://api-inference.huggingface.co/models/fofr/flux-condensation"
|
114 |
+
prompt = f"CONDENSATION, {prompt}"
|
115 |
+
if model == 'Flux Handwriting':
|
116 |
+
API_URL = "https://api-inference.huggingface.co/models/fofr/flux-handwriting"
|
117 |
+
prompt = f"HWRIT handwriting, {prompt}"
|
118 |
+
if model == 'Shou Xin':
|
119 |
+
API_URL = "https://api-inference.huggingface.co/models/Datou1111/shou_xin"
|
120 |
+
prompt = f"shou_xin, pencil sketch, {prompt}"
|
121 |
+
if model == 'Sketch Smudge':
|
122 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Sketch-Smudge-LoRA"
|
123 |
+
prompt = f"Sketch Smudge, {prompt}"
|
124 |
+
if model == '80s Cyberpunk':
|
125 |
+
API_URL = "https://api-inference.huggingface.co/models/fofr/flux-80s-cyberpunk"
|
126 |
+
prompt = f"80s cyberpunk, {prompt}"
|
127 |
+
if model == 'Coloring Book Flux':
|
128 |
+
API_URL = "https://api-inference.huggingface.co/models/renderartist/coloringbookflux"
|
129 |
+
prompt = f"c0l0ringb00k, coloring book, coloring book page, {prompt}"
|
130 |
+
if model == 'Flux Miniature LoRA':
|
131 |
+
API_URL = "https://api-inference.huggingface.co/models/gokaygokay/Flux-Miniature-LoRA"
|
132 |
+
prompt = f"MNTR, miniature drawing, {prompt}"
|
133 |
+
if model == 'Sketch Paint':
|
134 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Sketch-Paint"
|
135 |
+
prompt = f"Sketch paint, {prompt}"
|
136 |
+
if model == 'Flux UltraRealism 2.0':
|
137 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0"
|
138 |
+
prompt = f"Ultra realistic, {prompt}"
|
139 |
+
if model == 'Midjourney Mix':
|
140 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Midjourney-Mix-LoRA"
|
141 |
+
prompt = f"midjourney mix, {prompt}"
|
142 |
+
if model == 'Midjourney Mix 2':
|
143 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Midjourney-Mix2-LoRA"
|
144 |
+
prompt = f"MJ v6, {prompt}"
|
145 |
+
if model == 'Flux Logo Design':
|
146 |
+
API_URL = "https://api-inference.huggingface.co/models/Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design"
|
147 |
+
prompt = f"wablogo, logo, Minimalist, {prompt}"
|
148 |
+
if model == 'Flux Uncensored':
|
149 |
+
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
150 |
+
if model == 'Flux Uncensored V2':
|
151 |
+
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-Uncensored-V2"
|
152 |
+
if model == 'Flux Tarot Cards':
|
153 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Ton618-Tarot-Cards-Flux-LoRA"
|
154 |
+
prompt = f"Tarot card, {prompt}"
|
155 |
+
if model == 'Pixel Art Sprites':
|
156 |
+
API_URL = "https://api-inference.huggingface.co/models/sWizad/pokemon-trainer-sprites-pixelart-flux"
|
157 |
+
prompt = f"a pixel image, {prompt}"
|
158 |
+
if model == '3D Sketchfab':
|
159 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-3D-Sketchfab-Flux-LoRA"
|
160 |
+
prompt = f"3D Sketchfab, {prompt}"
|
161 |
+
if model == 'Retro Comic Flux':
|
162 |
+
API_URL = "https://api-inference.huggingface.co/models/renderartist/retrocomicflux"
|
163 |
+
prompt = f"c0m1c, comic book panel, {prompt}"
|
164 |
+
if model == 'Caricature':
|
165 |
+
API_URL = "https://api-inference.huggingface.co/models/TheAwakenOne/caricature"
|
166 |
+
prompt = f"CCTUR3, {prompt}"
|
167 |
+
if model == 'Huggieverse':
|
168 |
+
API_URL = "https://api-inference.huggingface.co/models/Chunte/flux-lora-Huggieverse"
|
169 |
+
prompt = f"HGGRE, {prompt}"
|
170 |
+
if model == 'Propaganda Poster':
|
171 |
+
API_URL = "https://api-inference.huggingface.co/models/AlekseyCalvin/Propaganda_Poster_Schnell_by_doctor_diffusion"
|
172 |
+
prompt = f"propaganda poster, {prompt}"
|
173 |
+
if model == 'Flux Game Assets V2':
|
174 |
+
API_URL = "https://api-inference.huggingface.co/models/gokaygokay/Flux-Game-Assets-LoRA-v2"
|
175 |
+
prompt = f"wbgmsst, white background, {prompt}"
|
176 |
+
if model == 'SDXL HS Card Style':
|
177 |
+
API_URL = "https://api-inference.huggingface.co/models/Norod78/sdxl-hearthstone-card-style-lora"
|
178 |
+
prompt = f"Hearthstone Card, {prompt}"
|
179 |
+
if model == 'SLDR FLUX NSFW v2 Studio':
|
180 |
+
API_URL = "https://api-inference.huggingface.co/models/xey/sldr_flux_nsfw_v2-studio"
|
181 |
+
if model == 'SoftPasty Flux':
|
182 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/softpasty-flux-dev"
|
183 |
+
prompt = f"araminta_illus illustration style, {prompt}"
|
184 |
+
if model == 'Flux Stickers':
|
185 |
+
API_URL = "https://api-inference.huggingface.co/models/diabolic6045/Flux_Sticker_Lora"
|
186 |
+
prompt = f"5t1cker 5ty1e, {prompt}"
|
187 |
+
if model == 'Flux Animex V2':
|
188 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animex-v2-LoRA"
|
189 |
+
prompt = f"Animex, {prompt}"
|
190 |
+
if model == 'Flux Animeo V1':
|
191 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animeo-v1-LoRA"
|
192 |
+
prompt = f"Animeo, {prompt}"
|
193 |
+
if model == 'Movie Board':
|
194 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux.1-Dev-Movie-Boards-LoRA"
|
195 |
+
prompt = f"movieboard, {prompt}"
|
196 |
+
if model == 'Purple Dreamy':
|
197 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Purple-Dreamy-Flux-LoRA"
|
198 |
+
prompt = f"Purple Dreamy, {prompt}"
|
199 |
+
if model == 'PS1 Style Flux':
|
200 |
+
API_URL = "https://api-inference.huggingface.co/models/veryVANYA/ps1-style-flux"
|
201 |
+
prompt = f"ps1 game screenshot, {prompt}"
|
202 |
+
if model == 'Softserve Anime':
|
203 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/softserve_anime"
|
204 |
+
prompt = f"sftsrv style illustration, {prompt}"
|
205 |
+
if model == 'Flux Tarot v1':
|
206 |
+
API_URL = "https://api-inference.huggingface.co/models/multimodalart/flux-tarot-v1"
|
207 |
+
prompt = f"in the style of TOK a trtcrd tarot style, {prompt}"
|
208 |
+
if model == 'Half Illustration':
|
209 |
+
API_URL = "https://api-inference.huggingface.co/models/davisbro/half_illustration"
|
210 |
+
prompt = f"in the style of TOK, {prompt}"
|
211 |
+
if model == 'OpenDalle v1.1':
|
212 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
|
213 |
+
if model == 'Flux Ghibsky Illustration':
|
214 |
+
API_URL = "https://api-inference.huggingface.co/models/aleksa-codes/flux-ghibsky-illustration"
|
215 |
+
prompt = f"GHIBSKY style, {prompt}"
|
216 |
+
if model == 'Flux Koda':
|
217 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/flux-koda"
|
218 |
+
prompt = f"flmft style, {prompt}"
|
219 |
+
if model == 'Soviet Diffusion XL':
|
220 |
+
API_URL = "https://api-inference.huggingface.co/models/openskyml/soviet-diffusion-xl"
|
221 |
+
prompt = f"soviet poster, {prompt}"
|
222 |
+
if model == 'Flux Realism LoRA':
|
223 |
+
API_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
|
224 |
+
if model == 'Frosting Lane Flux':
|
225 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/frosting_lane_flux"
|
226 |
+
prompt = f"frstingln illustration, {prompt}"
|
227 |
+
if model == 'Phantasma Anime':
|
228 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/phantasma-anime"
|
229 |
+
if model == 'Boreal':
|
230 |
+
API_URL = "https://api-inference.huggingface.co/models/kudzueye/Boreal"
|
231 |
+
prompt = f"photo, {prompt}"
|
232 |
+
if model == 'How2Draw':
|
233 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/how2draw"
|
234 |
+
prompt = f"How2Draw, {prompt}"
|
235 |
+
if model == 'Flux AestheticAnime':
|
236 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-AestheticAnime"
|
237 |
+
if model == 'Fashion Hut Modeling LoRA':
|
238 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA"
|
239 |
+
prompt = f"Modeling of, {prompt}"
|
240 |
+
if model == 'Flux SyntheticAnime':
|
241 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-SyntheticAnime"
|
242 |
+
prompt = f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}"
|
243 |
+
if model == 'Flux Midjourney Anime':
|
244 |
+
API_URL = "https://api-inference.huggingface.co/models/brushpenbob/flux-midjourney-anime"
|
245 |
+
prompt = f"egmid, {prompt}"
|
246 |
+
if model == 'Coloring Book Generator':
|
247 |
+
API_URL = "https://api-inference.huggingface.co/models/robert123231/coloringbookgenerator"
|
248 |
+
if model == 'Collage Flux':
|
249 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-Collage-Dim-Flux-LoRA"
|
250 |
+
prompt = f"collage, {prompt}"
|
251 |
+
if model == 'Flux Product Ad Backdrop':
|
252 |
+
API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Product-Ad-Backdrop"
|
253 |
+
prompt = f"Product Ad, {prompt}"
|
254 |
+
if model == 'Product Design':
|
255 |
+
API_URL = "https://api-inference.huggingface.co/models/multimodalart/product-design"
|
256 |
+
prompt = f"product designed by prdsgn, {prompt}"
|
257 |
+
if model == '90s Anime Art':
|
258 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/90s-anime-art"
|
259 |
+
if model == 'Brain Melt Acid Art':
|
260 |
+
API_URL = "https://api-inference.huggingface.co/models/glif/Brain-Melt-Acid-Art"
|
261 |
+
prompt = f"maximalism, in an acid surrealism style, {prompt}"
|
262 |
+
if model == 'Lustly Flux Uncensored v1':
|
263 |
+
API_URL = "https://api-inference.huggingface.co/models/lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1"
|
264 |
+
if model == 'NSFW Master Flux':
|
265 |
+
API_URL = "https://api-inference.huggingface.co/models/Keltezaa/NSFW_MASTER_FLUX"
|
266 |
+
prompt = f"NSFW, {prompt}"
|
267 |
+
if model == 'Flux Outfit Generator':
|
268 |
+
API_URL = "https://api-inference.huggingface.co/models/tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator"
|
269 |
+
if model == 'Midjourney':
|
270 |
+
API_URL = "https://api-inference.huggingface.co/models/Jovie/Midjourney"
|
271 |
+
if model == 'DreamPhotoGASM':
|
272 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/DreamPhotoGASM"
|
273 |
+
if model == 'Flux Super Realism LoRA':
|
274 |
+
API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Super-Realism-LoRA"
|
275 |
+
if model == 'Stable Diffusion 2-1':
|
276 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1-base"
|
277 |
+
if model == 'Stable Diffusion 3.5 Large':
|
278 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
|
279 |
+
if model == 'Stable Diffusion 3.5 Large Turbo':
|
280 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large-turbo"
|
281 |
+
if model == 'Stable Diffusion 3 Medium':
|
282 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
|
283 |
+
prompt = f"A, {prompt}"
|
284 |
+
|
285 |
+
# Adjust URL for different providers if needed
|
286 |
+
base_url = "https://api-inference.huggingface.co"
|
287 |
+
if provider == "fal-ai":
|
288 |
+
base_url = "https://api.fal.ai/hf"
|
289 |
+
elif provider == "nebius":
|
290 |
+
base_url = "https://api.nebius.ai/hf"
|
291 |
+
elif provider == "replicate":
|
292 |
+
base_url = "https://api.replicate.com/v1/models"
|
293 |
+
# Replicate has a different endpoint structure
|
294 |
+
if "https://api-inference.huggingface.co/models/" in API_URL:
|
295 |
+
model_id = API_URL.replace("https://api-inference.huggingface.co/models/", "")
|
296 |
+
API_URL = f"{base_url}/{model_id}"
|
297 |
+
elif provider == "together":
|
298 |
+
base_url = "https://api.together.xyz/inference"
|
299 |
+
if "https://api-inference.huggingface.co/models/" in API_URL:
|
300 |
+
model_id = API_URL.replace("https://api-inference.huggingface.co/models/", "")
|
301 |
+
API_URL = f"{base_url}/{model_id}"
|
302 |
|
303 |
+
# Only update URL if we're not using a custom URL format (like for replicate)
|
304 |
+
if provider != "replicate" and provider != "together" and "https://api-inference.huggingface.co/models/" in API_URL:
|
305 |
+
model_id = API_URL.replace("https://api-inference.huggingface.co/models/", "")
|
306 |
+
API_URL = f"{base_url}/models/{model_id}"
|
307 |
+
|
308 |
+
print(f"API URL set to: {API_URL}") # Debug log
|
309 |
+
if model == 'Duchaiten Real3D NSFW XL':
|
310 |
+
API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/duchaiten-real3d-nsfw-xl"
|
311 |
+
if model == 'Pixel Art XL':
|
312 |
+
API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
|
313 |
+
prompt = f"pixel art, {prompt}"
|
314 |
+
if model == 'Character Design':
|
315 |
+
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/character-design"
|
316 |
+
prompt = f"Character Design, {prompt}"
|
317 |
+
if model == 'Sketched Out Manga':
|
318 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/sketchedoutmanga"
|
319 |
+
prompt = f"daiton, {prompt}"
|
320 |
+
if model == 'Archfey Anime':
|
321 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/archfey_anime"
|
322 |
+
if model == 'Lofi Cuties':
|
323 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/lofi-cuties"
|
324 |
+
if model == 'YiffyMix':
|
325 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/YiffyMix"
|
326 |
+
if model == 'Analog Madness Realistic v7':
|
327 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/AnalogMadness-realistic-model-v7"
|
328 |
+
if model == 'Selfie Photography':
|
329 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl"
|
330 |
+
prompt = f"instagram model, discord profile picture, {prompt}"
|
331 |
+
if model == 'Filmgrain':
|
332 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl"
|
333 |
+
prompt = f"Film Grain, FilmGrainAF, {prompt}"
|
334 |
+
if model == 'Leonardo AI Style Illustration':
|
335 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/Leonardo_Ai_Style_Illustration"
|
336 |
+
prompt = f"leonardo style, illustration, vector art, {prompt}"
|
337 |
+
if model == 'Cyborg Style XL':
|
338 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/cyborg_style_xl"
|
339 |
+
prompt = f"cyborg style, {prompt}"
|
340 |
+
if model == 'Little Tinies':
|
341 |
+
API_URL = "https://api-inference.huggingface.co/models/alvdansen/littletinies"
|
342 |
+
if model == 'NSFW XL':
|
343 |
+
API_URL = "https://api-inference.huggingface.co/models/Dremmar/nsfw-xl"
|
344 |
+
if model == 'Analog Redmond':
|
345 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/analogredmond"
|
346 |
+
prompt = f"timeless style, {prompt}"
|
347 |
+
if model == 'Pixel Art Redmond':
|
348 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/PixelArtRedmond"
|
349 |
+
prompt = f"Pixel Art, {prompt}"
|
350 |
+
if model == 'Ascii Art':
|
351 |
+
API_URL = "https://api-inference.huggingface.co/models/CiroN2022/ascii-art"
|
352 |
+
prompt = f"ascii art, {prompt}"
|
353 |
+
if model == 'Analog':
|
354 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/Analog"
|
355 |
+
if model == 'Maple Syrup':
|
356 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/MapleSyrup"
|
357 |
+
if model == 'Perfect Lewd Fantasy':
|
358 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/perfectLewdFantasy_v1.01"
|
359 |
+
if model == 'AbsoluteReality 1.8.1':
|
360 |
+
API_URL = "https://api-inference.huggingface.co/models/digiplay/AbsoluteReality_v1.8.1"
|
361 |
+
if model == 'Disney':
|
362 |
+
API_URL = "https://api-inference.huggingface.co/models/goofyai/disney_style_xl"
|
363 |
+
prompt = f"Disney style, {prompt}"
|
364 |
+
if model == 'Redmond SDXL':
|
365 |
+
API_URL = "https://api-inference.huggingface.co/models/artificialguybr/LogoRedmond-LogoLoraForSDXL-V2"
|
366 |
+
if model == 'epiCPhotoGasm':
|
367 |
+
API_URL = "https://api-inference.huggingface.co/models/Yntec/epiCPhotoGasm"
|
368 |
+
print(f"API URL set to: {API_URL}") # Debug log
|
369 |
|
370 |
# Define the payload for the request
|
371 |
payload = {
|
|
|
382 |
}
|
383 |
print(f"Payload: {json.dumps(payload, indent=2)}") # Debug log
|
384 |
|
385 |
+
# Adjust payload for different providers if needed
|
386 |
+
if provider == "replicate" or provider == "together":
|
387 |
+
# These providers might have different API formats
|
388 |
+
if provider == "replicate":
|
389 |
+
payload = {
|
390 |
+
"version": model_id,
|
391 |
+
"input": {
|
392 |
+
"prompt": prompt,
|
393 |
+
"negative_prompt": is_negative,
|
394 |
+
"num_inference_steps": steps,
|
395 |
+
"guidance_scale": cfg_scale,
|
396 |
+
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
397 |
+
"strength": strength,
|
398 |
+
"width": width,
|
399 |
+
"height": height
|
400 |
+
}
|
401 |
+
}
|
402 |
+
elif provider == "together":
|
403 |
+
payload = {
|
404 |
+
"model": model_id,
|
405 |
+
"prompt": prompt,
|
406 |
+
"negative_prompt": is_negative,
|
407 |
+
"num_inference_steps": steps,
|
408 |
+
"guidance_scale": cfg_scale,
|
409 |
+
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
410 |
+
"strength": strength,
|
411 |
+
"width": width,
|
412 |
+
"height": height
|
413 |
+
}
|
414 |
+
|
415 |
+
# Make a request to the API to generate the image
|
416 |
try:
|
417 |
+
# Log which provider we're using
|
418 |
+
print(f"Sending request to {provider} provider")
|
419 |
+
|
420 |
+
# Add provider to headers for HF inference if needed
|
421 |
+
if provider != "hf-inference" and "api-inference.huggingface.co" in API_URL:
|
422 |
+
headers["X-Provider"] = provider
|
423 |
+
|
424 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
425 |
print(f"Response status code: {response.status_code}") # Debug log
|
426 |
except requests.exceptions.RequestException as e:
|
427 |
# Log any request exceptions and raise an error for the user
|
|
|
446 |
raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
|
447 |
|
448 |
try:
|
449 |
+
# Handle different response formats based on provider
|
450 |
+
if provider == "replicate":
|
451 |
+
# Replicate might return a URL to the image rather than the image itself
|
452 |
+
result = response.json()
|
453 |
+
if "output" in result and isinstance(result["output"], list) and len(result["output"]) > 0:
|
454 |
+
image_url = result["output"][0]
|
455 |
+
# Fetch the image from the URL
|
456 |
+
image_response = requests.get(image_url, timeout=timeout)
|
457 |
+
image_bytes = image_response.content
|
458 |
+
else:
|
459 |
+
raise Exception(f"Unexpected Replicate response format: {result}")
|
460 |
+
else:
|
461 |
+
# Standard response with image content
|
462 |
+
image_bytes = response.content
|
463 |
+
|
464 |
image = Image.open(io.BytesIO(image_bytes))
|
465 |
print(f'Generation {key} completed! ({prompt})') # Debug log
|
466 |
return image
|
|
|
616 |
# Tab for advanced settings
|
617 |
with gr.Tab("Advanced Settings"):
|
618 |
with gr.Row():
|
619 |
+
# Textbox for specifying elements to exclude from the image
|
620 |
+
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")
|
621 |
+
|
622 |
+
with gr.Row():
|
623 |
+
# Provider selection radio buttons
|
624 |
+
providers_list = [
|
625 |
+
"hf-inference", # Default Hugging Face Inference
|
626 |
+
"fal-ai", # Fal.ai
|
627 |
+
"nebius", # Nebius
|
628 |
+
"replicate", # Replicate
|
629 |
+
"together", # Together AI
|
630 |
+
]
|
631 |
+
|
632 |
provider_radio = gr.Radio(
|
633 |
+
choices=providers_list,
|
634 |
value="hf-inference",
|
635 |
label="Inference Provider",
|
636 |
+
info="Select which provider to use for image generation. Providers other than HF Inference require a custom API key.",
|
637 |
+
elem_id="provider-radio"
|
638 |
)
|
639 |
+
|
640 |
with gr.Row():
|
641 |
# BYOK (Bring Your Own Key) textbox
|
642 |
byok_textbox = gr.Textbox(
|
643 |
value="",
|
644 |
label="BYOK (Bring Your Own Key)",
|
645 |
+
info="Enter a custom API key here. Required for all providers except HF Inference.",
|
646 |
placeholder="Enter your API token",
|
647 |
type="password", # Hide the API key for security
|
648 |
elem_id="byok-input"
|
649 |
)
|
650 |
+
|
651 |
+
# Function to validate provider selection based on BYOK
|
652 |
+
def validate_provider(api_key, provider):
|
653 |
+
# If no custom API key is provided, only "hf-inference" can be used
|
654 |
+
if not api_key.strip() and provider != "hf-inference":
|
655 |
+
return gr.update(value="hf-inference")
|
656 |
+
return gr.update(value=provider)
|
657 |
+
|
658 |
+
# Connect the BYOK textbox to validate provider selection
|
659 |
+
byok_textbox.change(
|
660 |
+
fn=validate_provider,
|
661 |
+
inputs=[byok_textbox, provider_radio],
|
662 |
+
outputs=provider_radio
|
663 |
+
)
|
664 |
+
|
665 |
+
# Also validate provider when the radio changes to ensure consistency
|
666 |
+
provider_radio.change(
|
667 |
+
fn=validate_provider,
|
668 |
+
inputs=[byok_textbox, provider_radio],
|
669 |
+
outputs=provider_radio
|
670 |
+
)
|
671 |
with gr.Row():
|
672 |
# Slider for selecting the image width
|
673 |
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
|
|
689 |
# Radio buttons for selecting the sampling method
|
690 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
691 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
# Tab for image editing options
|
693 |
with gr.Tab("Image Editor"):
|
694 |
# Function to simulate a delay for processing
|
|
|
746 |
"""
|
747 |
)
|
748 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
# Accordion providing an overview of advanced settings
|
750 |
with gr.Accordion("Advanced Settings Overview", open=False):
|
751 |
gr.Markdown(
|
752 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
753 |
## Negative Prompt
|
754 |
###### 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.
|
755 |
|
756 |
+
## Inference Provider
|
757 |
+
###### Select which AI provider to use for generating images. Different providers may have different capabilities, pricing, and performance characteristics:
|
758 |
+
###### - HF Inference: Default Hugging Face inference API (uses application's default keys)
|
759 |
+
###### - Fal AI: Optimized for low latency and high throughput (requires your own API key)
|
760 |
+
###### - Nebius: Cloud provider with enterprise-grade infrastructure (requires your own API key)
|
761 |
+
###### - Replicate: Wide variety of models with flexible deployment (requires your own API key)
|
762 |
+
###### - Together: High-performance inference service (requires your own API key)
|
763 |
+
|
764 |
+
## BYOK (Bring Your Own Key)
|
765 |
+
###### This allows you to use your own API key instead of the default keys. Enter your key here for direct access to models using your account's permissions and rate limits. A custom key is required for all providers except HF Inference.
|
766 |
+
|
767 |
## Width & Height
|
768 |
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
|
769 |
|
|
|
793 |
with gr.Row():
|
794 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
795 |
|
796 |
+
# Set up button click event to call the query function with provider and BYOK parameters
|
797 |
+
text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height, provider_radio, byok_textbox], outputs=image_output)
|
798 |
|
799 |
print("Launching Gradio interface...") # Debug log
|
800 |
# Launch the Gradio interface without showing the API or sharing externally
|