File size: 1,641 Bytes
0000954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2068d48
cd3ab0c
2068d48
 
 
 
 
cd3ab0c
 
2068d48
 
 
 
 
 
 
 
0000954
2068d48
 
 
 
 
 
18436a0
2068d48
 
 
18436a0
2068d48
 
7e14cc3
2068d48
 
18436a0
2068d48
18436a0
0000954
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
import gradio as gr
import os
from huggingface_hub import InferenceClient

# πŸ”‘ token
HF_TOKEN = os.getenv("image")

client = InferenceClient(
    model="stabilityai/stable-diffusion-xl-base-1.0",
    token=HF_TOKEN
)

def generate_image(prompt, width, height):
    if not prompt.strip():
        return None, "⚠️ Enter prompt"

    try:
        image = client.text_to_image(
            prompt,
            width=int(width),
            height=int(height)
        )
        return image, "βœ… Image generated"

    except Exception as e:
        return None, f"❌ Error: {str(e)}"


# 🎨 CLEAN MODERN UI
with gr.Blocks(
    theme=gr.themes.Soft(
        primary_hue="blue",
        secondary_hue="sky",
        neutral_hue="gray"
    )
) as app:

    # βœ… MAIN TITLE (fixed visibility)
    gr.Markdown(
        """
        # 🎨 AI Text β†’ Image Generator
        ### ✨ Generate high-quality AI images using Stable Diffusion
        """,
        elem_id="title"
    )

    with gr.Row():
        prompt = gr.Textbox(
            label="✍️ Enter Prompt",
            placeholder="A futuristic city at night, cinematic lighting...",
            lines=3
        )

    with gr.Row():
        width = gr.Slider(256, 1024, value=768, step=64, label="πŸ“ Width")
        height = gr.Slider(256, 1024, value=768, step=64, label="πŸ“ Height")

    with gr.Row():
        btn = gr.Button("πŸš€ Generate Image", variant="primary")

    output_img = gr.Image(label="πŸ–ΌοΈ Result", type="pil")
    status = gr.Textbox(label="πŸ“’ Status")

    btn.click(generate_image, [prompt, width, height], [output_img, status])

app.launch()