Spaces:
Paused
Paused
File size: 5,294 Bytes
a807c41 d6c7880 a807c41 d6c7880 a807c41 d6c7880 a807c41 d6c7880 a807c41 d6c7880 a807c41 d6c7880 a807c41 d6c7880 a807c41 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | """
Logo Creator - Generate professional logos using AI
Self-contained app using FLUX.1-schnell with ZeroGPU on HuggingFace Spaces
"""
import os
import random
import gradio as gr
import numpy as np
MAX_SEED = np.iinfo(np.int32).max
MODEL_ID = "black-forest-labs/FLUX.1-schnell"
def generate_logo(
prompt: str,
style: str,
color_scheme: str,
background: str,
seed: int,
randomize_seed: bool,
width: int,
height: int,
num_steps: int,
progress=gr.Progress(track_tqdm=True),
):
"""Generate a logo based on user inputs."""
import torch
from diffusers import FluxPipeline
if not prompt.strip():
raise gr.Error("Please enter a description for your logo.")
# Build enhanced prompt
parts = [
f"A professional logo design: {prompt.strip()}",
f"{style} style" if style != "Auto" else "",
f"{color_scheme} color scheme" if color_scheme != "Auto" else "",
f"{background} background" if background != "Auto" else "",
"clean vector art, high quality, centered composition, professional logo design",
]
full_prompt = ", ".join(p for p in parts if p)
if randomize_seed:
seed = random.randint(0, MAX_SEED)
pipe = FluxPipeline.from_pretrained(
MODEL_ID,
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
generator = torch.Generator("cuda").manual_seed(seed)
image = pipe(
prompt=full_prompt,
width=width,
height=height,
num_inference_steps=num_steps,
generator=generator,
guidance_scale=0.0,
).images[0]
return image, seed
# Apply ZeroGPU decorator if available
try:
import spaces
generate_logo = spaces.GPU(duration=120)(generate_logo)
print("ZeroGPU enabled")
except ImportError:
print("Running without ZeroGPU (local mode)")
# --- UI ---
STYLE_CHOICES = [
"Auto", "Minimalist", "Modern", "Vintage", "Geometric", "Abstract",
"Flat", "3D", "Hand-drawn", "Corporate", "Playful", "Elegant", "Tech", "Nature",
]
COLOR_CHOICES = [
"Auto", "Monochrome", "Blue tones", "Red tones", "Green tones",
"Gold and black", "Pastel", "Vibrant", "Earth tones", "Gradient", "Neon",
]
BG_CHOICES = ["Auto", "White", "Black", "Transparent-style", "Gradient"]
EXAMPLES = [
["A mountain peak with a rising sun for a travel company called Horizon", "Minimalist", "Blue tones", "White", 42, True, 1024, 1024, 4],
["A fox head for a tech startup called FoxByte", "Geometric", "Auto", "White", 42, True, 1024, 1024, 4],
["Coffee cup with steam forming a book for ReadBrew", "Modern", "Earth tones", "Auto", 42, True, 1024, 1024, 4],
["A rocket launching from a laptop for a SaaS company", "Flat", "Vibrant", "White", 42, True, 1024, 1024, 4],
["An elegant letter M with floral accents for a luxury brand", "Elegant", "Gold and black", "Black", 42, True, 1024, 1024, 4],
]
with gr.Blocks(
theme=gr.themes.Soft(),
title="Logo Creator",
css=".main-header { text-align: center; margin-bottom: 0.5em; } .generate-btn { min-height: 50px !important; }",
) as demo:
gr.Markdown("# Logo Creator", elem_classes="main-header")
gr.Markdown("Generate professional logos with AI. Describe your logo idea and customize the style.")
with gr.Row():
with gr.Column(scale=1):
prompt = gr.Textbox(
label="Logo Description",
placeholder="Describe the logo you want to create...",
lines=3,
)
style = gr.Dropdown(choices=STYLE_CHOICES, value="Auto", label="Style")
color_scheme = gr.Dropdown(choices=COLOR_CHOICES, value="Auto", label="Color Scheme")
background = gr.Dropdown(choices=BG_CHOICES, value="Auto", label="Background")
with gr.Accordion("Advanced Settings", open=False):
seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=42, label="Seed")
randomize_seed = gr.Checkbox(value=True, label="Randomize Seed")
with gr.Row():
width = gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Width")
height = gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Height")
num_steps = gr.Slider(minimum=1, maximum=8, step=1, value=4, label="Inference Steps")
generate_btn = gr.Button("Generate Logo", variant="primary", elem_classes="generate-btn")
with gr.Column(scale=1):
output_image = gr.Image(label="Generated Logo", type="pil")
output_seed = gr.Number(label="Seed Used", interactive=False)
generate_btn.click(
fn=generate_logo,
inputs=[prompt, style, color_scheme, background, seed, randomize_seed, width, height, num_steps],
outputs=[output_image, output_seed],
)
gr.Examples(
examples=EXAMPLES,
inputs=[prompt, style, color_scheme, background, seed, randomize_seed, width, height, num_steps],
outputs=[output_image, output_seed],
fn=generate_logo,
cache_examples=False,
)
gr.Markdown("---\n*Powered by [FLUX.1-schnell](https://huggingface.co/black-forest-labs/FLUX.1-schnell) with ZeroGPU*")
if __name__ == "__main__":
demo.launch()
|