Spestly's picture
Create app.py
f053400 verified
raw
history blame
3.4 kB
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()