Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
ADDING CUSTOM PROVIDERS AND BYOK
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ 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
|
@@ -25,6 +25,7 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
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:
|
@@ -35,10 +36,16 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
|
|
35 |
key = random.randint(0, 999)
|
36 |
print(f"Generated key: {key}") # Debug log
|
37 |
|
38 |
-
#
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
@@ -530,6 +537,16 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
530 |
with gr.Row():
|
531 |
# Textbox for specifying elements to exclude from the image
|
532 |
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
533 |
with gr.Row():
|
534 |
# Slider for selecting the image width
|
535 |
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
@@ -615,6 +632,9 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
615 |
## Negative Prompt
|
616 |
###### 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.
|
617 |
|
|
|
|
|
|
|
618 |
## Width & Height
|
619 |
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
|
620 |
|
@@ -644,8 +664,8 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
|
|
644 |
with gr.Row():
|
645 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
646 |
|
647 |
-
# Set up button click event to call the query function
|
648 |
-
text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
|
649 |
|
650 |
print("Launching Gradio interface...") # Debug log
|
651 |
# Launch the Gradio interface without showing the API or sharing externally
|
|
|
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, custom_api_key=""):
|
21 |
# Debug log to indicate function start
|
22 |
print("Starting query function...")
|
23 |
# Print the parameters for debugging purposes
|
|
|
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 |
+
print(f"Custom API Key provided: {bool(custom_api_key.strip())}") # Log whether a custom key was provided without printing the key
|
29 |
|
30 |
# Check if the prompt is empty or None
|
31 |
if prompt == "" or prompt is None:
|
|
|
36 |
key = random.randint(0, 999)
|
37 |
print(f"Generated key: {key}") # Debug log
|
38 |
|
39 |
+
# Determine which token to use - custom API key if provided, otherwise one of the environment variables
|
40 |
+
if custom_api_key.strip() != "":
|
41 |
+
print("USING CUSTOM API KEY: BYOK token provided by user is being used for authentication")
|
42 |
+
API_TOKEN = custom_api_key.strip()
|
43 |
+
else:
|
44 |
+
# Randomly select an API token from available options to distribute the load
|
45 |
+
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")])
|
46 |
+
print("USING DEFAULT API KEY: Random environment variable token is being used for authentication")
|
47 |
+
|
48 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
|
49 |
|
50 |
# Enhance the prompt with additional details for better quality
|
51 |
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
|
|
537 |
with gr.Row():
|
538 |
# Textbox for specifying elements to exclude from the image
|
539 |
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")
|
540 |
+
with gr.Row():
|
541 |
+
# New: BYOK (Bring Your Own Key) textbox
|
542 |
+
byok_textbox = gr.Textbox(
|
543 |
+
value="",
|
544 |
+
label="BYOK (Bring Your Own Key)",
|
545 |
+
info="Enter a custom Hugging Face API key here. When provided, this key will be used instead of the default keys.",
|
546 |
+
placeholder="Enter your Hugging Face API token",
|
547 |
+
type="password", # Hide the API key for security
|
548 |
+
elem_id="byok-input"
|
549 |
+
)
|
550 |
with gr.Row():
|
551 |
# Slider for selecting the image width
|
552 |
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
|
|
632 |
## Negative Prompt
|
633 |
###### 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.
|
634 |
|
635 |
+
## BYOK (Bring Your Own Key)
|
636 |
+
###### This allows you to use your own Hugging Face API key instead of the default keys. Enter your key here for direct access to models using your account's permissions and rate limits.
|
637 |
+
|
638 |
## Width & Height
|
639 |
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
|
640 |
|
|
|
664 |
with gr.Row():
|
665 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
666 |
|
667 |
+
# Set up button click event to call the query function with the added BYOK parameter
|
668 |
+
text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height, byok_textbox], outputs=image_output)
|
669 |
|
670 |
print("Launching Gradio interface...") # Debug log
|
671 |
# Launch the Gradio interface without showing the API or sharing externally
|