File size: 2,447 Bytes
ea7bda6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c74cf43
 
 
ea7bda6
 
 
 
 
c74cf43
 
 
ea7bda6
 
 
 
 
 
c74cf43
ea7bda6
 
 
 
 
c74cf43
ea7bda6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380a40a
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
import os
import gradio as gr
from main import StableDiffusionEngine

# Load Hugging Face token from environment
HF_TOKEN = os.getenv("HF_TOKEN")

# Initialize Stable Diffusion engine
sd_engine = StableDiffusionEngine(hf_token=HF_TOKEN)


def generate(prompt, steps, cfg, width, height):
    """
    Wrapper function for Gradio UI.
    """
    return sd_engine.generate_image(
        prompt=prompt,
        num_inference_steps=steps,
        guidance_scale=cfg,
        width=width,
        height=height,
    )


examples = [
    "A futuristic African city at sunset, ultra realistic, cinematic lighting",
    "A microscopic view of malaria parasites, scientific illustration",
    "A humanoid AI researcher working in a high-tech laboratory",
]


with gr.Blocks(theme=gr.themes.Soft(), title="Stable Diffusion Research Lab") as demo:
    gr.Markdown(
        """
        # 🧠 Stable Diffusion Research Lab
        **Text-to-Image Generation using SDXL**
        
        This app is designed for **research and experimentation** with Stable Diffusion models.
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="Describe the image you want to generate...",
                lines=4,
            )

            steps = gr.Slider(
                minimum=5,
                maximum=20,
                value=10,
                step=1,
                label="Inference Steps",
            )

            cfg = gr.Slider(
                minimum=5.0,
                maximum=9.0,
                value=6.0,
                step=0.5,
                label="Guidance Scale (CFG)",
            )

            width = gr.Dropdown(
                choices=[512, 768, 1024],
                value=768,
                label="Image Width",
            )

            height = gr.Dropdown(
                choices=[512, 768, 1024],
                value=512,
                label="Image Height",
            )

            generate_btn = gr.Button("🚀 Generate Image", variant="primary")

        with gr.Column(scale=1):
            output = gr.Image(
                label="Generated Image",
                type="pil",
            )

    gr.Examples(examples=examples, inputs=prompt)

    generate_btn.click(
        fn=generate,
        inputs=[prompt, steps, cfg, width, height],
        outputs=output,
    )

demo.launch(debug=True)