Update app.py
Browse files
app.py
CHANGED
@@ -6,30 +6,30 @@ import os
|
|
6 |
from PIL import Image
|
7 |
from deep_translator import GoogleTranslator
|
8 |
|
9 |
-
#os.makedirs('assets', exist_ok=True)
|
10 |
if not os.path.exists('icon.jpg'):
|
11 |
os.system("wget -O icon.jpg https://i.pinimg.com/564x/64/49/88/644988c59447eb00286834c2e70fdd6b.jpg")
|
12 |
-
API_URL_DEV ="https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
13 |
-
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
|
14 |
timeout = 100
|
15 |
|
16 |
-
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, huggingface_api_key=None):
|
|
|
|
|
|
|
17 |
# Check if the request is an API call by checking for the presence of the huggingface_api_key
|
18 |
is_api_call = huggingface_api_key is not None
|
19 |
|
20 |
if is_api_call:
|
21 |
-
|
22 |
# Use the environment variable for the API key in GUI mode
|
23 |
API_TOKEN = os.getenv("HF_READ_TOKEN")
|
24 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
25 |
-
|
26 |
else:
|
27 |
# Validate the API key if it's an API call
|
28 |
if huggingface_api_key == "":
|
29 |
raise gr.Error("API key is required for API calls.")
|
30 |
-
|
31 |
headers = {"Authorization": f"Bearer {huggingface_api_key}"}
|
32 |
-
|
33 |
if prompt == "" or prompt is None:
|
34 |
return None
|
35 |
|
@@ -54,7 +54,7 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
54 |
"strength": strength
|
55 |
}
|
56 |
|
57 |
-
response = requests.post(
|
58 |
if response.status_code != 200:
|
59 |
print(f"Error: Failed to get image. Response status: {response.status_code}")
|
60 |
print(f"Response content: {response.text}")
|
@@ -87,13 +87,11 @@ css = """
|
|
87 |
align-items: center;
|
88 |
justify-content: center;
|
89 |
}
|
90 |
-
|
91 |
#title-icon {
|
92 |
width: 32px; /* Adjust the width of the icon as needed */
|
93 |
height: auto;
|
94 |
margin-right: 10px; /* Space between icon and title */
|
95 |
}
|
96 |
-
|
97 |
#title-text {
|
98 |
font-size: 24px; /* Adjust font size as needed */
|
99 |
font-weight: bold;
|
@@ -124,16 +122,15 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
|
124 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
125 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
126 |
huggingface_api_key = gr.Textbox(label="Hugging Face API Key (required for API calls)", placeholder="Enter your Hugging Face API Key here", type="password", elem_id="api-key")
|
|
|
127 |
|
128 |
with gr.Row():
|
129 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
130 |
with gr.Row():
|
131 |
-
# Define two outputs: one for the image file path and one for the seed
|
132 |
-
#image_path_output = gr.Textbox(label="Image File Path", elem_id="gallery")
|
133 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
134 |
seed_output = gr.Textbox(label="Seed Used", elem_id="seed-output")
|
135 |
|
136 |
-
# Adjust the click function to include the API key as
|
137 |
-
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, huggingface_api_key], outputs=[image_output, seed_output])
|
138 |
|
139 |
app.launch(show_api=True, share=False)
|
|
|
6 |
from PIL import Image
|
7 |
from deep_translator import GoogleTranslator
|
8 |
|
9 |
+
# os.makedirs('assets', exist_ok=True)
|
10 |
if not os.path.exists('icon.jpg'):
|
11 |
os.system("wget -O icon.jpg https://i.pinimg.com/564x/64/49/88/644988c59447eb00286834c2e70fdd6b.jpg")
|
12 |
+
API_URL_DEV = "https://lol-v2.mxflower.eu.org/api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
13 |
+
API_URL = "https://lol-v2.mxflower.eu.org/api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
|
14 |
timeout = 100
|
15 |
|
16 |
+
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, huggingface_api_key=None, use_dev=False):
|
17 |
+
# Determine which API URL to use
|
18 |
+
api_url = API_URL_DEV if use_dev else API_URL
|
19 |
+
|
20 |
# Check if the request is an API call by checking for the presence of the huggingface_api_key
|
21 |
is_api_call = huggingface_api_key is not None
|
22 |
|
23 |
if is_api_call:
|
|
|
24 |
# Use the environment variable for the API key in GUI mode
|
25 |
API_TOKEN = os.getenv("HF_READ_TOKEN")
|
26 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
|
27 |
else:
|
28 |
# Validate the API key if it's an API call
|
29 |
if huggingface_api_key == "":
|
30 |
raise gr.Error("API key is required for API calls.")
|
|
|
31 |
headers = {"Authorization": f"Bearer {huggingface_api_key}"}
|
32 |
+
|
33 |
if prompt == "" or prompt is None:
|
34 |
return None
|
35 |
|
|
|
54 |
"strength": strength
|
55 |
}
|
56 |
|
57 |
+
response = requests.post(api_url, headers=headers, json=payload, timeout=timeout)
|
58 |
if response.status_code != 200:
|
59 |
print(f"Error: Failed to get image. Response status: {response.status_code}")
|
60 |
print(f"Response content: {response.text}")
|
|
|
87 |
align-items: center;
|
88 |
justify-content: center;
|
89 |
}
|
|
|
90 |
#title-icon {
|
91 |
width: 32px; /* Adjust the width of the icon as needed */
|
92 |
height: auto;
|
93 |
margin-right: 10px; /* Space between icon and title */
|
94 |
}
|
|
|
95 |
#title-text {
|
96 |
font-size: 24px; /* Adjust font size as needed */
|
97 |
font-weight: bold;
|
|
|
122 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
123 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
124 |
huggingface_api_key = gr.Textbox(label="Hugging Face API Key (required for API calls)", placeholder="Enter your Hugging Face API Key here", type="password", elem_id="api-key")
|
125 |
+
use_dev = gr.Checkbox(label="Use Dev API", value=False, elem_id="use-dev-checkbox")
|
126 |
|
127 |
with gr.Row():
|
128 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
129 |
with gr.Row():
|
|
|
|
|
130 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
131 |
seed_output = gr.Textbox(label="Seed Used", elem_id="seed-output")
|
132 |
|
133 |
+
# Adjust the click function to include the API key and use_dev as inputs
|
134 |
+
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, huggingface_api_key, use_dev], outputs=[image_output, seed_output])
|
135 |
|
136 |
app.launch(show_api=True, share=False)
|