Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -173,7 +173,7 @@ def generate_image_openai(
|
|
| 173 |
"n": n_images,
|
| 174 |
}
|
| 175 |
|
| 176 |
-
#
|
| 177 |
allowed_qualities = {"low", "medium", "high", "auto"}
|
| 178 |
if quality in allowed_qualities:
|
| 179 |
kwargs["quality"] = quality
|
|
@@ -225,9 +225,8 @@ def generate_image_google(
|
|
| 225 |
seed: Optional[int],
|
| 226 |
) -> List[Image.Image]:
|
| 227 |
"""
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
differently, tweak this function.
|
| 231 |
"""
|
| 232 |
genai = _configure_google(api_key)
|
| 233 |
model = genai.GenerativeModel(google_image_model)
|
|
@@ -409,6 +408,48 @@ def run_generation(
|
|
| 409 |
return f"Error during generation: {e}", [], "\n".join(debug_lines)
|
| 410 |
|
| 411 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
# -----------------------
|
| 413 |
# UI
|
| 414 |
# -----------------------
|
|
@@ -416,13 +457,13 @@ def run_generation(
|
|
| 416 |
with gr.Blocks() as demo:
|
| 417 |
gr.Markdown(
|
| 418 |
"""
|
| 419 |
-
# 𧬠ZEN
|
| 420 |
|
| 421 |
-
|
| 422 |
|
| 423 |
-
- π Bring your own OpenAI
|
| 424 |
- π¨ Generate **images** with presets + fine-grained controls
|
| 425 |
-
- π§ Generate **text** and **infographic specs** for ZEN dashboards,
|
| 426 |
"""
|
| 427 |
)
|
| 428 |
|
|
@@ -453,6 +494,26 @@ Multi-provider creator for the ZEN ecosystem:
|
|
| 453 |
label="Primary Provider",
|
| 454 |
)
|
| 455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
base_prompt = gr.Textbox(
|
| 457 |
label="Main Prompt",
|
| 458 |
lines=5,
|
|
@@ -539,7 +600,9 @@ Multi-provider creator for the ZEN ecosystem:
|
|
| 539 |
placeholder="Used internally as default text model.",
|
| 540 |
)
|
| 541 |
|
| 542 |
-
|
|
|
|
|
|
|
| 543 |
|
| 544 |
with gr.Column():
|
| 545 |
gr.Markdown("### π Text / Spec Output")
|
|
@@ -558,6 +621,7 @@ Multi-provider creator for the ZEN ecosystem:
|
|
| 558 |
lines=12,
|
| 559 |
)
|
| 560 |
|
|
|
|
| 561 |
generate_btn.click(
|
| 562 |
fn=run_generation,
|
| 563 |
inputs=[
|
|
@@ -580,5 +644,17 @@ Multi-provider creator for the ZEN ecosystem:
|
|
| 580 |
outputs=[text_output, image_gallery, debug_output],
|
| 581 |
)
|
| 582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
if __name__ == "__main__":
|
| 584 |
demo.launch()
|
|
|
|
| 173 |
"n": n_images,
|
| 174 |
}
|
| 175 |
|
| 176 |
+
# Allowed values from API: low, medium, high, auto
|
| 177 |
allowed_qualities = {"low", "medium", "high", "auto"}
|
| 178 |
if quality in allowed_qualities:
|
| 179 |
kwargs["quality"] = quality
|
|
|
|
| 225 |
seed: Optional[int],
|
| 226 |
) -> List[Image.Image]:
|
| 227 |
"""
|
| 228 |
+
Uses a Google / Gemini image-capable model that returns inline image bytes.
|
| 229 |
+
If your Nano-Banana model behaves differently, adjust this function.
|
|
|
|
| 230 |
"""
|
| 231 |
genai = _configure_google(api_key)
|
| 232 |
model = genai.GenerativeModel(google_image_model)
|
|
|
|
| 408 |
return f"Error during generation: {e}", [], "\n".join(debug_lines)
|
| 409 |
|
| 410 |
|
| 411 |
+
# -----------------------
|
| 412 |
+
# Starter prompts helper
|
| 413 |
+
# -----------------------
|
| 414 |
+
|
| 415 |
+
STARTER_PROMPTS = {
|
| 416 |
+
"None": "",
|
| 417 |
+
"ZEN Glass Arena Card": (
|
| 418 |
+
"ZEN AI Arena holographic credential card showcasing a youth AI pioneer, "
|
| 419 |
+
"glassmorphism border, quantum prism edges, subtle neon glow, "
|
| 420 |
+
"nameplate and role, dark control-room background"
|
| 421 |
+
),
|
| 422 |
+
"AI Pioneer Infographic": (
|
| 423 |
+
"Infographic showing the AI Pioneer Program journey from idea to deployment, "
|
| 424 |
+
"timeline of modules, icons for coding, Hugging Face Spaces, and blockchain credentials, "
|
| 425 |
+
"Palantir-style layout with three main columns"
|
| 426 |
+
),
|
| 427 |
+
"Youth AI Literacy Poster": (
|
| 428 |
+
"Poster inviting teens to join the AI Pioneer Program, diverse students, laptops, "
|
| 429 |
+
"cloud-hosted AI agents floating as holograms, bold headline and simple CTA, "
|
| 430 |
+
"modern but serious aesthetic"
|
| 431 |
+
),
|
| 432 |
+
"Vanguard Systems Blueprint": (
|
| 433 |
+
"Blueprint diagram of the ZEN ecosystem: AI Pioneer Program, ZEN Arena, "
|
| 434 |
+
"blockchain credentials, ZEN dashboards, arrows showing data flow and automations, "
|
| 435 |
+
"technical engineering style"
|
| 436 |
+
),
|
| 437 |
+
"Instructor Training Card": (
|
| 438 |
+
"Training card for ZEN Vanguard instructors with modules listed, clean UI, "
|
| 439 |
+
"minimal layout, white card on dark background, subtle gradient border, "
|
| 440 |
+
"space for QR code and URL"
|
| 441 |
+
),
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def load_starter_prompt(choice: str) -> str:
|
| 446 |
+
return STARTER_PROMPTS.get(choice, "")
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def clear_outputs():
|
| 450 |
+
return "", [], ""
|
| 451 |
+
|
| 452 |
+
|
| 453 |
# -----------------------
|
| 454 |
# UI
|
| 455 |
# -----------------------
|
|
|
|
| 457 |
with gr.Blocks() as demo:
|
| 458 |
gr.Markdown(
|
| 459 |
"""
|
| 460 |
+
# 𧬠ZEN Module 2 Section 2.11 β Omni Studio
|
| 461 |
|
| 462 |
+
A multi-provider creator used in the **ZEN Vanguard Program**.
|
| 463 |
|
| 464 |
+
- π Bring your own **OpenAI** and **Google (Gemini / Nano-Banana)** keys
|
| 465 |
- π¨ Generate **images** with presets + fine-grained controls
|
| 466 |
+
- π§ Generate **text** and **infographic specs** for ZEN dashboards, cards, and posters
|
| 467 |
"""
|
| 468 |
)
|
| 469 |
|
|
|
|
| 494 |
label="Primary Provider",
|
| 495 |
)
|
| 496 |
|
| 497 |
+
with gr.Accordion("Starter Prompts (ZEN Vanguard)", open=False):
|
| 498 |
+
starter_choice = gr.Dropdown(
|
| 499 |
+
list(STARTER_PROMPTS.keys()),
|
| 500 |
+
value="None",
|
| 501 |
+
label="Choose a starter prompt",
|
| 502 |
+
)
|
| 503 |
+
load_prompt_btn = gr.Button("Load Starter Prompt")
|
| 504 |
+
|
| 505 |
+
gr.Markdown(
|
| 506 |
+
"""
|
| 507 |
+
Use starter prompts to quickly explore:
|
| 508 |
+
|
| 509 |
+
- **ZEN Glass Arena Card** β holographic card-style image
|
| 510 |
+
- **AI Pioneer Infographic** β program journey and outcomes
|
| 511 |
+
- **Youth AI Literacy Poster** β outreach poster for teens
|
| 512 |
+
- **Vanguard Systems Blueprint** β systems-thinking diagram
|
| 513 |
+
- **Instructor Training Card** β card UI for trainers
|
| 514 |
+
"""
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
base_prompt = gr.Textbox(
|
| 518 |
label="Main Prompt",
|
| 519 |
lines=5,
|
|
|
|
| 600 |
placeholder="Used internally as default text model.",
|
| 601 |
)
|
| 602 |
|
| 603 |
+
with gr.Row():
|
| 604 |
+
generate_btn = gr.Button("π Generate", variant="primary")
|
| 605 |
+
clear_btn = gr.Button("Clear Outputs")
|
| 606 |
|
| 607 |
with gr.Column():
|
| 608 |
gr.Markdown("### π Text / Spec Output")
|
|
|
|
| 621 |
lines=12,
|
| 622 |
)
|
| 623 |
|
| 624 |
+
# Wire up callbacks
|
| 625 |
generate_btn.click(
|
| 626 |
fn=run_generation,
|
| 627 |
inputs=[
|
|
|
|
| 644 |
outputs=[text_output, image_gallery, debug_output],
|
| 645 |
)
|
| 646 |
|
| 647 |
+
load_prompt_btn.click(
|
| 648 |
+
fn=load_starter_prompt,
|
| 649 |
+
inputs=[starter_choice],
|
| 650 |
+
outputs=[base_prompt],
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
clear_btn.click(
|
| 654 |
+
fn=clear_outputs,
|
| 655 |
+
inputs=[],
|
| 656 |
+
outputs=[text_output, image_gallery, debug_output],
|
| 657 |
+
)
|
| 658 |
+
|
| 659 |
if __name__ == "__main__":
|
| 660 |
demo.launch()
|