Spaces:
Sleeping
Sleeping
File size: 2,159 Bytes
a28d291 08803c4 |
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 |
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline
MODEL_ID = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(
MODEL_ID,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
)
if torch.cuda.is_available():
pipe = pipe.to("cuda")
STYLES = {
"None": "",
"Cinematic": "cinematic lighting, dramatic, ultra detailed",
"Anime": "anime style, vibrant colors, sharp lines",
"Oil Painting": "oil painting, textured brush strokes",
"Cyberpunk": "cyberpunk, neon lights, futuristic",
"Fantasy Art": "fantasy art, magical, epic composition"
}
def generate(prompt, style, steps, guidance):
full_prompt = prompt
if STYLES[style]:
full_prompt = f"{prompt}, {STYLES[style]}"
image = pipe(
prompt=full_prompt,
num_inference_steps=steps,
guidance_scale=guidance
).images[0]
return image
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
gr.Markdown(
"""
# ✨ Instruct Image
Create images from text instructions using AI.
"""
)
with gr.Row():
with gr.Column(scale=1):
prompt = gr.Textbox(
label="Instruction",
placeholder="A futuristic city at night with glowing neon lights",
lines=3
)
style = gr.Dropdown(
choices=list(STYLES.keys()),
value="None",
label="Style"
)
steps = gr.Slider(15, 50, value=30, step=1, label="Steps")
guidance = gr.Slider(1, 15, value=7.5, step=0.5, label="Guidance")
generate_btn = gr.Button("✨ Generate Image", variant="primary")
with gr.Column(scale=1):
output = gr.Image(label="Result", height=512)
generate_btn.click(
fn=generate,
inputs=[prompt, style, steps, guidance],
outputs=output
)
gr.Markdown(
"""
**Model:** Stable Diffusion v1.5
**Note:** This demo is for creative and educational use.
"""
)
demo.launch()
|