File size: 8,493 Bytes
3b41516
 
 
 
 
 
0533eb4
 
 
 
3b41516
0533eb4
 
 
 
 
 
 
 
 
 
 
 
3b41516
 
0533eb4
 
3b41516
0533eb4
 
3b41516
0533eb4
3b41516
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0533eb4
 
 
3b41516
0533eb4
 
3b41516
0533eb4
 
 
3b41516
0533eb4
3b41516
 
0533eb4
 
 
 
 
 
3b41516
0533eb4
 
3b41516
0533eb4
 
 
3b41516
 
0533eb4
 
 
 
 
 
 
 
 
 
 
 
3b41516
0533eb4
 
 
3b41516
 
 
 
 
 
 
 
0533eb4
 
 
3b41516
0533eb4
 
3b41516
0533eb4
3b41516
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0533eb4
3b41516
0533eb4
3b41516
 
 
 
 
 
 
0533eb4
 
 
 
 
 
 
 
 
 
 
3b41516
0533eb4
 
 
 
 
 
 
3b41516
 
 
 
 
 
 
0533eb4
 
 
 
 
 
 
 
 
 
 
 
 
 
3b41516
0533eb4
 
 
 
3b41516
 
 
 
 
 
0533eb4
 
3b41516
 
0533eb4
 
 
 
 
3b41516
0533eb4
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
"""
Dispatch AI — Wallpaper Engine
Gradio app generating phone wallpapers with FLUX.1-schnell.
Presets: UAE Sunset, Cyberpunk, Minimal Dark, Arabic Calligraphy + more.
"""

import os
import io
import gradio as gr
from huggingface_hub import InferenceClient
from PIL import Image, ImageDraw

# --- Configuration -----------------------------------------------------------
HF_TOKEN = os.environ.get("HF_TOKEN", None)
MODEL_ID = "black-forest-labs/FLUX.1-schnell"

client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)

BG_COLOR = "#0A0F1A"
ACCENT = "#1FE0E6"

# Aspect ratio -> (width, height)
ASPECT_RATIOS = {
    "9:16 (Phone Wallpaper)": (720, 1280),
    "9:16 HD (Phone)": (1080, 1920),
    "1:1 (Square)": (1024, 1024),
    "16:9 (Wide)": (1280, 720),
    "4:5 (Portrait)": (1024, 1280),
}

# Presets: name -> (prompt, emoji)
PRESETS = {
    "UAE Sunset": (
        "A breathtaking UAE desert sunset, golden sand dunes rolling under a vibrant orange and purple sky, "
        "silhouette of a lone camel walking, distant wind tower, cinematic lighting, ultra detailed, 4k wallpaper",
        "🏜️",
    ),
    "Cyberpunk City": (
        "A neon-soaked cyberpunk city at night, towering skyscrapers with glowing cyan and magenta lights, "
        "flying cars, rain-slicked streets reflecting neon, blade runner aesthetic, ultra detailed wallpaper",
        "🌃",
    ),
    "Minimal Dark": (
        "Minimalist dark abstract wallpaper, deep black background with subtle geometric cyan lines, "
        "smooth gradients, modern elegant design, 4k",
        "⬛",
    ),
    "Arabic Calligraphy": (
        "Beautiful Arabic calligraphy art wallpaper, elegant flowing script in gold on dark textured background, "
        "intricate decorative borders, luxurious design, 4k",
        "✒️",
    ),
    "Desert Stars": (
        "A serene Arabian desert at night under a sky full of stars, Milky Way galaxy visible, "
        "soft sand dunes in foreground, peaceful cosmic atmosphere, ultra detailed wallpaper",
        "🌌",
    ),
    "Dubai Skyline": (
        "Dubai skyline at golden hour, Burj Khalifa towering above modern skyscrapers, warm sunlight, "
        "palm trees, luxury cars on Sheikh Zayed Road, cinematic, ultra detailed, 4k wallpaper",
        "🏙️",
    ),
    "Ocean Waves": (
        "Tranquil ocean waves wallpaper, deep blue water with white foam, sunlight sparkling on the surface, "
        "minimalist calming aesthetic, top-down view, ultra detailed, 4k",
        "🌊",
    ),
    "Mountain Peak": (
        "Majestic snow-capped mountain peak at dawn, alpine glow, dramatic clouds, pristine landscape, "
        "ultra detailed nature wallpaper, 4k",
        "🏔️",
    ),
    "Abstract Neon": (
        "Abstract neon wallpaper, flowing liquid metal shapes in cyan and purple, dark background, "
        "futuristic 3D render, ultra sharp, 4k",
        "🎨",
    ),
    "Falcon Majesty": (
        "A majestic falcon perched on a rock in the Arabian desert, piercing eyes, detailed feathers, "
        "warm sunset light, ultra detailed wildlife wallpaper, 4k",
        "🦅",
    ),
}


def generate_wallpaper(prompt, aspect, preset, num_steps):
    """Generate a wallpaper via FLUX.1-schnell."""
    if preset and preset in PRESETS:
        final_prompt = PRESETS[preset][0]
    elif prompt and prompt.strip():
        final_prompt = prompt.strip()
    else:
        final_prompt = PRESETS["UAE Sunset"][0]

    w, h = ASPECT_RATIOS.get(aspect, (720, 1280))
    steps = int(num_steps) if num_steps else 4

    try:
        image = client.text_to_image(
            final_prompt,
            width=w,
            height=h,
            num_inference_steps=steps,
        )
        if not isinstance(image, Image.Image):
            image = Image.open(io.BytesIO(image)) if hasattr(image, "read") else Image.open(image)
        return image, "✅ Wallpaper generated successfully!"
    except Exception as e:
        img = Image.new("RGB", (w, h), BG_COLOR)
        d = ImageDraw.Draw(img)
        d.text((w // 4, h // 2), f"Error: {str(e)[:60]}", fill=ACCENT)
        return img, f"❌ Error: {str(e)}"


def download_image(img):
    if img is None:
        return None
    path = os.path.join(os.getcwd(), "wallpaper_output.png")
    img.save(path)
    return path


def pick_preset_prompt(preset_name):
    return PRESETS.get(preset_name, ("", ""))[0]


# --- UI -----------------------------------------------------------------------
CSS = """
#dispatch-header h1 {
    color: #FFFFFF; font-size: 2.2rem; margin: 0;
    background: linear-gradient(90deg, #1FE0E6 0%, #FFFFFF 60%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
#dispatch-header p { color: #1FE0E6; font-size: 1.05rem; margin: 6px 0 0 0; }
.dispatch-footer { text-align: center; color: #8A8F9C; font-size: 0.9rem; padding-top: 8px; }
"""

with gr.Blocks(
    title="Dispatch AI — Wallpaper Engine",
    theme=gr.themes.Base(
        primary_hue="cyan",
        secondary_hue="cyan",
        neutral_hue="slate",
        font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui"],
    ).set(
        body_background_fill="#0A0F1A",
        body_background_fill_dark="#0A0F1A",
        body_text_color="#FFFFFF",
        body_text_color_dark="#FFFFFF",
        block_background_fill="#0E1424",
        block_background_fill_dark="#0E1424",
        block_border_color="#1FE0E6",
        block_border_width="1px",
        block_label_text_color="#1FE0E6",
        block_title_text_color="#1FE0E6",
        button_primary_background_fill="#1FE0E6",
        button_primary_background_fill_dark="#1FE0E6",
        button_primary_text_color="#0A0F1A",
        button_primary_border_color="#1FE0E6",
        input_background_fill="#0E1424",
        input_background_fill_dark="#0E1424",
        input_border_color="#1FE0E6",
        input_border_width="1px",
    ),
    css=CSS,
) as demo:
    with gr.Column(elem_id="dispatch-header"):
        gr.Markdown(
            """
            # Dispatch AI — Wallpaper Engine
            Generate stunning phone wallpapers with FLUX.1-schnell · Dispatch AI (FZE) · UAE
            """
        )

    with gr.Row():
        with gr.Column(scale=1):
            prompt_input = gr.Textbox(
                label="Prompt",
                placeholder="Describe your wallpaper... or pick a preset below",
                lines=3,
            )
            aspect_select = gr.Radio(
                list(ASPECT_RATIOS.keys()),
                label="Aspect Ratio",
                value="9:16 (Phone Wallpaper)",
            )
            preset_select = gr.Dropdown(
                list(PRESETS.keys()),
                label="Preset",
                value=None,
                info="Select a preset to auto-fill the prompt",
            )
            steps_slider = gr.Slider(
                minimum=1, maximum=8, value=4, step=1,
                label="Inference Steps (schnell works well at 4)",
            )
            with gr.Row():
                load_preset_btn = gr.Button("Load Preset", variant="secondary")
                generate_btn = gr.Button("🎨 Generate Wallpaper", variant="primary")
        with gr.Column(scale=2):
            output_image = gr.Image(
                label="Generated Wallpaper",
                type="pil",
                show_download_button=True,
            )
            status_box = gr.Textbox(label="Status", interactive=False)
            download_btn = gr.Button("⬇️ Download PNG", variant="secondary")
            download_file = gr.File(label="Download")

    # Events
    load_preset_btn.click(pick_preset_prompt, inputs=preset_select, outputs=prompt_input)
    generate_btn.click(
        generate_wallpaper,
        inputs=[prompt_input, aspect_select, preset_select, steps_slider],
        outputs=[output_image, status_box],
    )
    download_btn.click(download_image, inputs=output_image, outputs=download_file)

    gr.Examples(
        examples=[[v[0], "9:16 (Phone Wallpaper)", k, 4] for k, v in PRESETS.items()],
        inputs=[prompt_input, aspect_select, preset_select, steps_slider],
        label="Preset Examples — click to load",
    )

    gr.Markdown(
        """
        <div class="dispatch-footer">
        © 2026 Dispatch AI (FZE) · UAE · License 10818 · Model: FLUX.1-schnell by Black Forest Labs
        </div>
        """
    )

if __name__ == "__main__":
    demo.queue()
    demo.launch()