Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from diffusers import DiffusionPipeline | |
import torch | |
import spaces | |
model_options = { | |
"OdysseyXL V2.5": "Spestly/OdysseyXL-V2.5", | |
"OdysseyXL V2": "Spestly/OdysseyXL-V2", | |
"OdysseyXL V1": "Spestly/OdysseyXL-V1", | |
} | |
# Cache for loaded pipelines | |
loaded_pipelines = {} | |
def load_model(model_name): | |
model_id = model_options[model_name] | |
if model_name not in loaded_pipelines: | |
pipe = DiffusionPipeline.from_pretrained( | |
model_id, | |
torch_dtype=torch.float16, | |
use_safetensors=True | |
) | |
pipe.to("cuda") | |
loaded_pipelines[model_name] = pipe | |
return loaded_pipelines[model_name] | |
def generate_image(model_name, prompt, negative_prompt, guidance_scale, num_inference_steps): | |
pipe = load_model(model_name) | |
image = pipe( | |
prompt=prompt, | |
negative_prompt=negative_prompt, | |
guidance_scale=guidance_scale, | |
num_inference_steps=num_inference_steps | |
).images[0] | |
return image | |
# --- Gradio UI --- | |
with gr.Blocks(css="style.css", theme='NoCrypt/miku') as demo: | |
gr.Markdown("# π¨ OdysseyXL Image Generation") | |
gr.Markdown("Choose from multiple OdysseyXL model versions running on ZeroGPU (H200).") | |
with gr.Row(): | |
with gr.Column(scale=2): | |
model_name = gr.Dropdown( | |
label="Model Version", | |
choices=list(model_options.keys()), | |
value="OdysseyXL V2.5" | |
) | |
prompt = gr.Textbox( | |
label="Prompt", | |
max_lines=2, | |
placeholder="Enter your prompt", | |
) | |
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=[ | |
["OdysseyXL V2.5", "A futuristic cityscape, vibrant neon colors, ultra-realistic, 8K", "blurry, low quality", 7.5, 30], | |
["OdysseyXL V2", "A majestic lion with a crown of stars, cosmic background, fantasy art", "cartoon, sketch", 8.0, 40], | |
["OdysseyXL V1", "An enchanted forest at night, glowing mushrooms, fireflies, mystical atmosphere", "daytime, bright", 7.0, 35], | |
], | |
inputs=[model_name, prompt, negative_prompt, guidance_scale, num_inference_steps], | |
outputs=image_output, | |
fn=generate_image, | |
cache_examples=True | |
) | |
run_button.click( | |
fn=generate_image, | |
inputs=[model_name, prompt, negative_prompt, guidance_scale, num_inference_steps], | |
outputs=image_output | |
) | |
if __name__ == "__main__": | |
demo.launch() | |