Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,31 +40,34 @@ pipe.enable_vae_slicing()
|
|
| 40 |
pipe.set_progress_bar_config(disable=True)
|
| 41 |
|
| 42 |
# ===============================
|
| 43 |
-
# ULTRA MODE (
|
| 44 |
# ===============================
|
| 45 |
-
def call_ultra_api(prompt, steps, resolution, seed):
|
| 46 |
try:
|
| 47 |
-
# Connect specifically to the Z-Image-Turbo Space
|
| 48 |
client = Client("mrfakename/Z-Image-Turbo")
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
#
|
|
|
|
|
|
|
|
|
|
| 52 |
result = client.predict(
|
| 53 |
-
prompt=
|
| 54 |
-
height=int(resolution),
|
| 55 |
width=int(resolution),
|
|
|
|
| 56 |
num_inference_steps=int(steps),
|
| 57 |
seed=int(seed),
|
| 58 |
-
randomize_seed=False,
|
| 59 |
-
api_name="/
|
| 60 |
)
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
if isinstance(result,
|
| 64 |
return Image.open(result[0])
|
| 65 |
return Image.open(result)
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
-
print(f"
|
| 68 |
return None
|
| 69 |
|
| 70 |
# ===============================
|
|
@@ -72,12 +75,14 @@ def call_ultra_api(prompt, steps, resolution, seed):
|
|
| 72 |
# ===============================
|
| 73 |
def toggle_ultra(is_ultra):
|
| 74 |
if is_ultra:
|
|
|
|
| 75 |
return {
|
| 76 |
negative_field: gr.update(visible=True),
|
| 77 |
resolution: gr.update(choices=[512, 1024], value=512),
|
| 78 |
-
steps: gr.update(minimum=
|
| 79 |
}
|
| 80 |
else:
|
|
|
|
| 81 |
return {
|
| 82 |
negative_field: gr.update(visible=False),
|
| 83 |
resolution: gr.update(choices=[512, 768, 1024], value=512),
|
|
@@ -91,18 +96,19 @@ def generate(prompt, user_neg, res, step_val, is_ultra):
|
|
| 91 |
|
| 92 |
if is_ultra:
|
| 93 |
yield (None, "🎨 Generating Image...", gr.update(interactive=False))
|
| 94 |
-
# Ultra mode uses the direct prompt + user negative (if API supports neg,
|
| 95 |
-
# but Z-Turbo usually ignores neg prompt to stay 'Turbo')
|
| 96 |
-
# We pass the prompt combined with negative for best results if the API is simple
|
| 97 |
-
full_prompt = f"{prompt} | Negative: {user_neg}" if user_neg else prompt
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
if image:
|
| 102 |
-
yield (image, f"✅ Done
|
| 103 |
else:
|
| 104 |
-
yield (None, "❌ API
|
|
|
|
| 105 |
else:
|
|
|
|
| 106 |
yield (None, "🧠 Analysing Prompt", gr.update(interactive=False))
|
| 107 |
enhanced = enhance_prompt(prompt)
|
| 108 |
|
|
@@ -139,13 +145,21 @@ custom_css = """
|
|
| 139 |
|
| 140 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="green"), css=custom_css) as demo:
|
| 141 |
with gr.Column(elem_id="container"):
|
| 142 |
-
gr.Markdown("#
|
| 143 |
-
gr.Markdown("Generate images using Creeper AI
|
| 144 |
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Column(scale=1):
|
| 147 |
-
prompt_field = gr.Textbox(
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
with gr.Accordion("Settings ⚙️", open=True):
|
| 151 |
resolution = gr.Radio([512, 768, 1024], value=512, label="Resolution")
|
|
@@ -158,6 +172,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="green"), css=custom_css) as dem
|
|
| 158 |
output_img = gr.Image(label="Result", interactive=False)
|
| 159 |
status = gr.Markdown("🟢 Ready", elem_classes="status-box")
|
| 160 |
|
|
|
|
| 161 |
ultra_check.change(
|
| 162 |
toggle_ultra,
|
| 163 |
inputs=[ultra_check],
|
|
|
|
| 40 |
pipe.set_progress_bar_config(disable=True)
|
| 41 |
|
| 42 |
# ===============================
|
| 43 |
+
# ULTRA MODE (Z-IMAGE-TURBO)
|
| 44 |
# ===============================
|
| 45 |
+
def call_ultra_api(prompt, negative, steps, resolution, seed):
|
| 46 |
try:
|
|
|
|
| 47 |
client = Client("mrfakename/Z-Image-Turbo")
|
| 48 |
|
| 49 |
+
# The API doesn't support a separate 'negative_prompt' argument,
|
| 50 |
+
# so we append it to the main prompt for better adherence.
|
| 51 |
+
full_prompt = f"{prompt} . {negative}" if negative else prompt
|
| 52 |
+
|
| 53 |
+
# Call the specific endpoint defined in your HTML
|
| 54 |
result = client.predict(
|
| 55 |
+
prompt=full_prompt,
|
|
|
|
| 56 |
width=int(resolution),
|
| 57 |
+
height=int(resolution),
|
| 58 |
num_inference_steps=int(steps),
|
| 59 |
seed=int(seed),
|
| 60 |
+
randomize_seed=False, # We control the seed from Python
|
| 61 |
+
api_name="/generate_image"
|
| 62 |
)
|
| 63 |
|
| 64 |
+
# The API returns [image_filepath, seed_used]
|
| 65 |
+
if isinstance(result, (list, tuple)):
|
| 66 |
return Image.open(result[0])
|
| 67 |
return Image.open(result)
|
| 68 |
+
|
| 69 |
except Exception as e:
|
| 70 |
+
print(f"Ultra Mode Error: {e}")
|
| 71 |
return None
|
| 72 |
|
| 73 |
# ===============================
|
|
|
|
| 75 |
# ===============================
|
| 76 |
def toggle_ultra(is_ultra):
|
| 77 |
if is_ultra:
|
| 78 |
+
# Hide 768, extend steps to 20, show negative prompt
|
| 79 |
return {
|
| 80 |
negative_field: gr.update(visible=True),
|
| 81 |
resolution: gr.update(choices=[512, 1024], value=512),
|
| 82 |
+
steps: gr.update(minimum=1, maximum=20, value=9)
|
| 83 |
}
|
| 84 |
else:
|
| 85 |
+
# Normal mode settings
|
| 86 |
return {
|
| 87 |
negative_field: gr.update(visible=False),
|
| 88 |
resolution: gr.update(choices=[512, 768, 1024], value=512),
|
|
|
|
| 96 |
|
| 97 |
if is_ultra:
|
| 98 |
yield (None, "🎨 Generating Image...", gr.update(interactive=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
# Use user negative if provided, otherwise default
|
| 101 |
+
final_neg = user_neg if user_neg.strip() else default_neg
|
| 102 |
+
|
| 103 |
+
image = call_ultra_api(prompt, final_neg, step_val, size, seed)
|
| 104 |
|
| 105 |
if image:
|
| 106 |
+
yield (image, f"✅ Done (Ultra Mode). Seed: {seed}", gr.update(interactive=True))
|
| 107 |
else:
|
| 108 |
+
yield (None, "❌ API Busy or Error. Try again.", gr.update(interactive=True))
|
| 109 |
+
|
| 110 |
else:
|
| 111 |
+
# Normal CPU Mode
|
| 112 |
yield (None, "🧠 Analysing Prompt", gr.update(interactive=False))
|
| 113 |
enhanced = enhance_prompt(prompt)
|
| 114 |
|
|
|
|
| 145 |
|
| 146 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="green"), css=custom_css) as demo:
|
| 147 |
with gr.Column(elem_id="container"):
|
| 148 |
+
gr.Markdown("# 🎨 Creeper AI - v4.0")
|
| 149 |
+
gr.Markdown("Generate images using Creeper AI. Use **Ultra-Fast** for GPU speeds.")
|
| 150 |
|
| 151 |
with gr.Row():
|
| 152 |
with gr.Column(scale=1):
|
| 153 |
+
prompt_field = gr.Textbox(
|
| 154 |
+
label="What do you want to see?",
|
| 155 |
+
placeholder="e.g. A futuristic city",
|
| 156 |
+
lines=3
|
| 157 |
+
)
|
| 158 |
+
negative_field = gr.Textbox(
|
| 159 |
+
label="Negative Prompt",
|
| 160 |
+
value="blurry, low quality, distorted",
|
| 161 |
+
visible=False
|
| 162 |
+
)
|
| 163 |
|
| 164 |
with gr.Accordion("Settings ⚙️", open=True):
|
| 165 |
resolution = gr.Radio([512, 768, 1024], value=512, label="Resolution")
|
|
|
|
| 172 |
output_img = gr.Image(label="Result", interactive=False)
|
| 173 |
status = gr.Markdown("🟢 Ready", elem_classes="status-box")
|
| 174 |
|
| 175 |
+
# Connect the UI logic
|
| 176 |
ultra_check.change(
|
| 177 |
toggle_ultra,
|
| 178 |
inputs=[ultra_check],
|