Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
import spaces
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
# The model will be downloaded and cached the first time the app runs.
|
| 8 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
+
"Spestly/OdysseyXL_V2.5",
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
variant="fp16",
|
| 12 |
+
use_safetensors=True
|
| 13 |
+
)
|
| 14 |
+
# Move the pipeline to the GPU
|
| 15 |
+
pipe.to("cuda")
|
| 16 |
+
|
| 17 |
+
@spaces.GPU
|
| 18 |
+
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps):
|
| 19 |
+
"""
|
| 20 |
+
Generates an image from a text prompt using the OdysseyXL V2.5 model.
|
| 21 |
+
|
| 22 |
+
Args:
|
| 23 |
+
prompt (str): The text prompt to generate the image from.
|
| 24 |
+
negative_prompt (str): The negative text prompt.
|
| 25 |
+
guidance_scale (float): The guidance scale for the generation.
|
| 26 |
+
num_inference_steps (int): The number of inference steps.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
PIL.Image.Image: The generated image.
|
| 30 |
+
"""
|
| 31 |
+
image = pipe(
|
| 32 |
+
prompt=prompt,
|
| 33 |
+
negative_prompt=negative_prompt,
|
| 34 |
+
guidance_scale=guidance_scale,
|
| 35 |
+
num_inference_steps=num_inference_steps
|
| 36 |
+
).images[0]
|
| 37 |
+
return image
|
| 38 |
+
|
| 39 |
+
# --- Gradio Interface ---
|
| 40 |
+
|
| 41 |
+
with gr.Blocks(css="style.css") as demo:
|
| 42 |
+
gr.Markdown("# π¨ OdysseyXL V2.5 Image Generation")
|
| 43 |
+
gr.Markdown("A Gradio UI for the [Spestly/OdysseyXL V2.5](https://huggingface.co/Spestly/OdysseyXL%20V2.5) SDXL model, optimized for ZeroGPU.")
|
| 44 |
+
|
| 45 |
+
with gr.Row():
|
| 46 |
+
with gr.Column(scale=2):
|
| 47 |
+
prompt = gr.Textbox(
|
| 48 |
+
label="Prompt",
|
| 49 |
+
show_label=False,
|
| 50 |
+
max_lines=2,
|
| 51 |
+
placeholder="Enter your prompt",
|
| 52 |
+
container=False
|
| 53 |
+
)
|
| 54 |
+
negative_prompt = gr.Textbox(
|
| 55 |
+
label="Negative Prompt",
|
| 56 |
+
placeholder="Enter a negative prompt"
|
| 57 |
+
)
|
| 58 |
+
with gr.Row():
|
| 59 |
+
guidance_scale = gr.Slider(
|
| 60 |
+
label="Guidance Scale",
|
| 61 |
+
minimum=0,
|
| 62 |
+
maximum=20,
|
| 63 |
+
step=0.1,
|
| 64 |
+
value=7.5
|
| 65 |
+
)
|
| 66 |
+
num_inference_steps = gr.Slider(
|
| 67 |
+
label="Inference Steps",
|
| 68 |
+
minimum=10,
|
| 69 |
+
maximum=100,
|
| 70 |
+
step=1,
|
| 71 |
+
value=30
|
| 72 |
+
)
|
| 73 |
+
run_button = gr.Button("Generate Image", variant="primary")
|
| 74 |
+
with gr.Column(scale=1):
|
| 75 |
+
image_output = gr.Image(label="Generated Image", show_label=False)
|
| 76 |
+
|
| 77 |
+
gr.Examples(
|
| 78 |
+
examples=[
|
| 79 |
+
["A futuristic cityscape, vibrant neon colors, ultra-realistic, 8K", "blurry, low quality", 7.5, 30],
|
| 80 |
+
["A majestic lion with a crown of stars, cosmic background, fantasy art", "cartoon, sketch", 8.0, 40],
|
| 81 |
+
["An enchanted forest at night, glowing mushrooms, fireflies, mystical atmosphere", "daytime, bright", 7.0, 35],
|
| 82 |
+
["A delicious-looking gourmet burger on a wooden table, hyperrealistic food photography", "messy, unappetizing", 7.5, 25]
|
| 83 |
+
],
|
| 84 |
+
inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps],
|
| 85 |
+
outputs=image_output,
|
| 86 |
+
fn=generate_image,
|
| 87 |
+
cache_examples=True,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
run_button.click(
|
| 91 |
+
fn=generate_image,
|
| 92 |
+
inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps],
|
| 93 |
+
outputs=image_output
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
demo.launch()
|