remove comment
Browse files
app.py
CHANGED
|
@@ -100,11 +100,7 @@ def create_prompt(params):
|
|
| 100 |
|
| 101 |
|
| 102 |
def call_client(
|
| 103 |
-
prompt,
|
| 104 |
-
seed,
|
| 105 |
-
randomize_seed,
|
| 106 |
-
aspect_ratio,
|
| 107 |
-
num_inference_steps,
|
| 108 |
):
|
| 109 |
"""
|
| 110 |
Call the gradio client for image generation
|
|
@@ -124,11 +120,11 @@ def call_client(
|
|
| 124 |
resolution_map = {
|
| 125 |
"1:1": "1024x1024 ( 1:1 )",
|
| 126 |
"16:9": "1280x720 ( 16:9 )",
|
| 127 |
-
"
|
| 128 |
}
|
| 129 |
resolution = resolution_map.get(aspect_ratio, "1024x1024 ( 1:1 )")
|
| 130 |
|
| 131 |
-
client = Client("Tongyi-MAI/Z-Image-Turbo")
|
| 132 |
result = client.predict(
|
| 133 |
prompt=prompt,
|
| 134 |
resolution=resolution,
|
|
@@ -158,27 +154,33 @@ def run_inference_engine(
|
|
| 158 |
aspect_ratio,
|
| 159 |
guidance_scale,
|
| 160 |
num_inference_steps,
|
| 161 |
-
|
| 162 |
):
|
| 163 |
"""
|
| 164 |
generate UI button images
|
| 165 |
|
| 166 |
Args:
|
| 167 |
-
label (str): Text to display on the button
|
| 168 |
detail (str): Detailed design prompt
|
| 169 |
shape (str): Button shape ("box", "rounded", "oval", "free")
|
| 170 |
-
layout (str): Layout arrangement ("horizontal_3", "vertical_2", "box_2x2")
|
| 171 |
background (str): Background setting ("natural", "white", "black")
|
| 172 |
seed (int): Random seed value
|
| 173 |
randomize_seed (bool): Whether to randomize the seed
|
| 174 |
aspect_ratio (str): Image aspect ratio (use 1:1)
|
| 175 |
-
guidance_scale (float): Guidance scale (use 1)
|
| 176 |
-
num_inference_steps (int): Number of inference steps (use 8)
|
| 177 |
|
| 178 |
Yields:
|
| 179 |
tuple: (image, seed, status_message) - Generated image, used seed, status message
|
| 180 |
"""
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
yield None, seed, "Generating..."
|
| 183 |
prompt_params = {
|
| 184 |
"label": label,
|
|
@@ -190,16 +192,14 @@ def run_inference_engine(
|
|
| 190 |
prompt = create_prompt(prompt_params)
|
| 191 |
|
| 192 |
# Debug: Print the generated prompt
|
| 193 |
-
print(f"Generated prompt: {prompt}")
|
| 194 |
|
| 195 |
if randomize_seed:
|
| 196 |
seed = random.randint(0, MAX_SEED)
|
| 197 |
|
| 198 |
image, generated_seed, error = call_client(
|
| 199 |
-
prompt, seed, randomize_seed, aspect_ratio, num_inference_steps
|
| 200 |
)
|
| 201 |
-
print(type(image))
|
| 202 |
-
print(image)
|
| 203 |
|
| 204 |
if image is None:
|
| 205 |
gr.Warning(f"Error: {error}")
|
|
@@ -302,7 +302,7 @@ example_data = [
|
|
| 302 |
],
|
| 303 |
]
|
| 304 |
|
| 305 |
-
with gr.Blocks(css=css, theme=theme, title="UI Button Generator") as demo:
|
| 306 |
gr.Markdown("# 🎨 AI UI Button Generator")
|
| 307 |
gr.Markdown(
|
| 308 |
"<div class='subtitle'>UI button material and design concept generation tool using Z-Image-Turbo</div>"
|
|
@@ -358,7 +358,7 @@ with gr.Blocks(css=css, theme=theme, title="UI Button Generator") as demo:
|
|
| 358 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, render=False)
|
| 359 |
aspect_ratio = gr.Radio(
|
| 360 |
label="Aspect Ratio",
|
| 361 |
-
choices=["1:1", "16:9", "
|
| 362 |
value="1:1",
|
| 363 |
render=False,
|
| 364 |
)
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
def call_client(
|
| 103 |
+
prompt, seed, randomize_seed, aspect_ratio, num_inference_steps, hf_token=None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
):
|
| 105 |
"""
|
| 106 |
Call the gradio client for image generation
|
|
|
|
| 120 |
resolution_map = {
|
| 121 |
"1:1": "1024x1024 ( 1:1 )",
|
| 122 |
"16:9": "1280x720 ( 16:9 )",
|
| 123 |
+
"9:16": "720x1280 ( 9:16 )",
|
| 124 |
}
|
| 125 |
resolution = resolution_map.get(aspect_ratio, "1024x1024 ( 1:1 )")
|
| 126 |
|
| 127 |
+
client = Client("Tongyi-MAI/Z-Image-Turbo", hf_token=hf_token)
|
| 128 |
result = client.predict(
|
| 129 |
prompt=prompt,
|
| 130 |
resolution=resolution,
|
|
|
|
| 154 |
aspect_ratio,
|
| 155 |
guidance_scale,
|
| 156 |
num_inference_steps,
|
| 157 |
+
request: gr.Request,
|
| 158 |
):
|
| 159 |
"""
|
| 160 |
generate UI button images
|
| 161 |
|
| 162 |
Args:
|
| 163 |
+
label (str): Text to display on the button,allow empty
|
| 164 |
detail (str): Detailed design prompt
|
| 165 |
shape (str): Button shape ("box", "rounded", "oval", "free")
|
| 166 |
+
layout (str): Layout arrangement ("horizontal_3:3x1", "vertical_2:1x2", "box_2x2:2x2")
|
| 167 |
background (str): Background setting ("natural", "white", "black")
|
| 168 |
seed (int): Random seed value
|
| 169 |
randomize_seed (bool): Whether to randomize the seed
|
| 170 |
aspect_ratio (str): Image aspect ratio (use 1:1)
|
| 171 |
+
guidance_scale (float): Guidance scale (use 1),no need to change
|
| 172 |
+
num_inference_steps (int): Number of inference steps (use 8),no need to change
|
| 173 |
|
| 174 |
Yields:
|
| 175 |
tuple: (image, seed, status_message) - Generated image, used seed, status message
|
| 176 |
"""
|
| 177 |
+
hf_token = HF_TOKEN
|
| 178 |
+
if request:
|
| 179 |
+
if hasattr(request, "headers"):
|
| 180 |
+
if hasattr(request.headers, "authorization"):
|
| 181 |
+
hf_token = request.headers.authorization
|
| 182 |
+
# print(hf_token)
|
| 183 |
+
|
| 184 |
yield None, seed, "Generating..."
|
| 185 |
prompt_params = {
|
| 186 |
"label": label,
|
|
|
|
| 192 |
prompt = create_prompt(prompt_params)
|
| 193 |
|
| 194 |
# Debug: Print the generated prompt
|
| 195 |
+
# print(f"Generated prompt: {prompt}")
|
| 196 |
|
| 197 |
if randomize_seed:
|
| 198 |
seed = random.randint(0, MAX_SEED)
|
| 199 |
|
| 200 |
image, generated_seed, error = call_client(
|
| 201 |
+
prompt, seed, randomize_seed, aspect_ratio, num_inference_steps, hf_token
|
| 202 |
)
|
|
|
|
|
|
|
| 203 |
|
| 204 |
if image is None:
|
| 205 |
gr.Warning(f"Error: {error}")
|
|
|
|
| 302 |
],
|
| 303 |
]
|
| 304 |
|
| 305 |
+
with gr.Blocks(css=css, theme=theme, title="UI Button Generator MCP") as demo:
|
| 306 |
gr.Markdown("# 🎨 AI UI Button Generator")
|
| 307 |
gr.Markdown(
|
| 308 |
"<div class='subtitle'>UI button material and design concept generation tool using Z-Image-Turbo</div>"
|
|
|
|
| 358 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, render=False)
|
| 359 |
aspect_ratio = gr.Radio(
|
| 360 |
label="Aspect Ratio",
|
| 361 |
+
choices=["1:1", "16:9", "9:16"],
|
| 362 |
value="1:1",
|
| 363 |
render=False,
|
| 364 |
)
|