File size: 3,399 Bytes
f053400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from diffusers import DiffusionPipeline
import torch
import spaces

# Load the model
# The model will be downloaded and cached the first time the app runs.
pipe = DiffusionPipeline.from_pretrained(
    "Spestly/OdysseyXL_V2.5", 
    torch_dtype=torch.float16, 
    variant="fp16",
    use_safetensors=True
)
# Move the pipeline to the GPU
pipe.to("cuda")

@spaces.GPU
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps):
    """
    Generates an image from a text prompt using the OdysseyXL V2.5 model.

    Args:
        prompt (str): The text prompt to generate the image from.
        negative_prompt (str): The negative text prompt.
        guidance_scale (float): The guidance scale for the generation.
        num_inference_steps (int): The number of inference steps.

    Returns:
        PIL.Image.Image: The generated image.
    """
    image = pipe(
        prompt=prompt, 
        negative_prompt=negative_prompt,
        guidance_scale=guidance_scale,
        num_inference_steps=num_inference_steps
    ).images[0]
    return image

# --- Gradio Interface ---

with gr.Blocks(css="style.css") as demo:
    gr.Markdown("# 🎨 OdysseyXL V2.5 Image Generation")
    gr.Markdown("A Gradio UI for the [Spestly/OdysseyXL V2.5](https://huggingface.co/Spestly/OdysseyXL%20V2.5) SDXL model, optimized for ZeroGPU.")
    
    with gr.Row():
        with gr.Column(scale=2):
            prompt = gr.Textbox(
                label="Prompt", 
                show_label=False, 
                max_lines=2, 
                placeholder="Enter your prompt",
                container=False
            )
            negative_prompt = gr.Textbox(
                label="Negative Prompt",
                placeholder="Enter a negative prompt"
            )
            with gr.Row():
                guidance_scale = gr.Slider(
                    label="Guidance Scale", 
                    minimum=0, 
                    maximum=20, 
                    step=0.1, 
                    value=7.5
                )
                num_inference_steps = gr.Slider(
                    label="Inference Steps",
                    minimum=10,
                    maximum=100,
                    step=1,
                    value=30
                )
            run_button = gr.Button("Generate Image", variant="primary")
        with gr.Column(scale=1):
            image_output = gr.Image(label="Generated Image", show_label=False)

    gr.Examples(
        examples=[
            ["A futuristic cityscape, vibrant neon colors, ultra-realistic, 8K", "blurry, low quality", 7.5, 30],
            ["A majestic lion with a crown of stars, cosmic background, fantasy art", "cartoon, sketch", 8.0, 40],
            ["An enchanted forest at night, glowing mushrooms, fireflies, mystical atmosphere", "daytime, bright", 7.0, 35],
            ["A delicious-looking gourmet burger on a wooden table, hyperrealistic food photography", "messy, unappetizing", 7.5, 25]
        ],
        inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps],
        outputs=image_output,
        fn=generate_image,
        cache_examples=True,
    )

    run_button.click(
        fn=generate_image, 
        inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps],
        outputs=image_output
    )

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