Spaces:
Running on Zero
Running on Zero
Full loading UI on the result during generation; examples load silently
Browse files
app.py
CHANGED
|
@@ -162,39 +162,43 @@ def generate(prompt, images=None, aspect=AUTO, resolution="4 MP", seed=0, random
|
|
| 162 |
|
| 163 |
|
| 164 |
def studio(state, seed, randomize, effort):
|
| 165 |
-
"""The composer's Generate: optional PE (streamed)
|
| 166 |
state = state or {}
|
| 167 |
prompt = (state.get("prompt") or "").strip()
|
| 168 |
aspect = state.get("aspect") or AUTO
|
| 169 |
resolution = state.get("resolution") or "4 MP"
|
| 170 |
if not prompt:
|
| 171 |
raise gr.Error("Describe the image first.")
|
| 172 |
-
|
| 173 |
if randomize:
|
| 174 |
seed = random.randint(0, MAX_SEED)
|
| 175 |
final, thinking = prompt, ""
|
| 176 |
if state.get("enhance") and paths:
|
| 177 |
gr.Info("Prompt enhancement is text-to-image only for now; edits use your prompt as written.")
|
| 178 |
elif state.get("enhance"):
|
| 179 |
-
yield
|
| 180 |
t0 = time.time()
|
| 181 |
caption = ratio = None
|
| 182 |
for thinking, caption, ratio in enhance_stream(prompt, effort, seed):
|
| 183 |
if caption is None:
|
| 184 |
-
yield
|
| 185 |
if caption:
|
| 186 |
final = caption
|
| 187 |
if aspect == AUTO and ratio:
|
| 188 |
aspect = ratio
|
| 189 |
-
yield
|
| 190 |
width, height = resolve_size(paths, aspect, resolution)
|
| 191 |
-
yield
|
| 192 |
-
embeds_path, seed, width, height = prepare(final,
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
yield path, f"{width}×{height} · seed {seed} · {time.time() - t0:.0f}s", final, thinking, seed
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
IDEAS = [
|
| 200 |
"a two-color risograph print of a fox reading a newspaper on a park bench, headline \"FOX NEWS\"",
|
|
@@ -485,14 +489,19 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="MiniMax H3 Image") as d
|
|
| 485 |
with gr.Accordion("Enhancer thinking", open=False):
|
| 486 |
thinking = gr.Textbox(show_label=False, lines=10)
|
| 487 |
|
|
|
|
| 488 |
composer.submit(
|
| 489 |
-
|
|
|
|
|
|
|
| 490 |
show_progress="minimal", api_visibility="private",
|
|
|
|
|
|
|
| 491 |
)
|
| 492 |
|
| 493 |
composer.apply(
|
| 494 |
load_example, [composer], [output, stats, prompt_used, thinking],
|
| 495 |
-
show_progress="
|
| 496 |
)
|
| 497 |
|
| 498 |
# Plain API endpoint (also what the composer runs, minus the streaming UI updates).
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
def studio(state, seed, randomize, effort):
|
| 165 |
+
"""The composer's Generate, part 1: optional PE (streamed) and encoding. Returns the render plan."""
|
| 166 |
state = state or {}
|
| 167 |
prompt = (state.get("prompt") or "").strip()
|
| 168 |
aspect = state.get("aspect") or AUTO
|
| 169 |
resolution = state.get("resolution") or "4 MP"
|
| 170 |
if not prompt:
|
| 171 |
raise gr.Error("Describe the image first.")
|
| 172 |
+
paths = decode_pictures(state.get("images"))
|
| 173 |
if randomize:
|
| 174 |
seed = random.randint(0, MAX_SEED)
|
| 175 |
final, thinking = prompt, ""
|
| 176 |
if state.get("enhance") and paths:
|
| 177 |
gr.Info("Prompt enhancement is text-to-image only for now; edits use your prompt as written.")
|
| 178 |
elif state.get("enhance"):
|
| 179 |
+
yield "✨ Enhancing the prompt with MiniMax-H3-Image-PE ...", gr.update(), "", seed, None
|
| 180 |
t0 = time.time()
|
| 181 |
caption = ratio = None
|
| 182 |
for thinking, caption, ratio in enhance_stream(prompt, effort, seed):
|
| 183 |
if caption is None:
|
| 184 |
+
yield f"✨ Enhancing the prompt · thinking ({len(thinking.split())} words) ...", gr.update(), thinking, seed, None
|
| 185 |
if caption:
|
| 186 |
final = caption
|
| 187 |
if aspect == AUTO and ratio:
|
| 188 |
aspect = ratio
|
| 189 |
+
yield f"✨ Prompt enhanced in {time.time() - t0:.0f}s · encoding ...", final, thinking, seed, None
|
| 190 |
width, height = resolve_size(paths, aspect, resolution)
|
| 191 |
+
yield f"Encoding the prompt · {width}×{height} ...", final, thinking, seed, None
|
| 192 |
+
embeds_path, seed, width, height = prepare(final, paths, aspect, resolution, seed, False)
|
| 193 |
+
plan = {"embeds": embeds_path, "images": paths, "width": width, "height": height, "seed": seed}
|
| 194 |
+
yield f"Generating {width}×{height} ...", final, thinking, seed, plan
|
| 195 |
+
|
|
|
|
| 196 |
|
| 197 |
+
def render(plan):
|
| 198 |
+
"""Part 2: the image, as its own event so the result panel shows the normal loading UI."""
|
| 199 |
+
t0 = time.time()
|
| 200 |
+
path = _generate(plan["embeds"], plan["images"], plan["width"], plan["height"], plan["seed"])
|
| 201 |
+
return path, f"{plan['width']}×{plan['height']} · seed {plan['seed']} · {time.time() - t0:.0f}s"
|
| 202 |
|
| 203 |
IDEAS = [
|
| 204 |
"a two-color risograph print of a fox reading a newspaper on a park bench, headline \"FOX NEWS\"",
|
|
|
|
| 489 |
with gr.Accordion("Enhancer thinking", open=False):
|
| 490 |
thinking = gr.Textbox(show_label=False, lines=10)
|
| 491 |
|
| 492 |
+
plan = gr.State()
|
| 493 |
composer.submit(
|
| 494 |
+
lambda: (None, None), None, [output, plan], show_progress="hidden", api_visibility="private",
|
| 495 |
+
).then(
|
| 496 |
+
studio, [composer, seed, randomize, effort], [stats, prompt_used, thinking, seed, plan],
|
| 497 |
show_progress="minimal", api_visibility="private",
|
| 498 |
+
).success(
|
| 499 |
+
render, [plan], [output, stats], show_progress="full", show_progress_on=[output], api_visibility="private",
|
| 500 |
)
|
| 501 |
|
| 502 |
composer.apply(
|
| 503 |
load_example, [composer], [output, stats, prompt_used, thinking],
|
| 504 |
+
show_progress="hidden", api_visibility="private",
|
| 505 |
)
|
| 506 |
|
| 507 |
# Plain API endpoint (also what the composer runs, minus the streaming UI updates).
|