Spaces:
Running
on
Zero
Running
on
Zero
Ahmad Basyouni
commited on
Commit
•
867f594
1
Parent(s):
7690ab1
Add application file
Browse files
app.py
CHANGED
@@ -6,15 +6,15 @@ import numpy as np
|
|
6 |
|
7 |
# Load Stable Diffusion pipeline
|
8 |
model_id = "CompVis/stable-diffusion-v1-4"
|
9 |
-
default_scheduler =
|
10 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=default_scheduler, torch_dtype=torch.
|
11 |
-
pipe = pipe.to("cpu")
|
12 |
|
13 |
# Scheduler options
|
14 |
schedulers = {
|
|
|
15 |
"Artistic & Imaginative (Euler Ancestral) - Recommended for creative scenes, moderate speed": EulerAncestralDiscreteScheduler,
|
16 |
"Photo-Realistic (PNDM) - Best for realistic details, moderate speed": PNDMScheduler,
|
17 |
-
"High-Definition & Fast (DDIM) - Good quality with fastest speed": DDIMScheduler,
|
18 |
}
|
19 |
|
20 |
# Main image generation function with dynamic scheduling and size option
|
@@ -34,7 +34,7 @@ def generate_image(prompt, use_categories, genre, style, theme, lighting, schedu
|
|
34 |
pipe.scheduler = scheduler
|
35 |
|
36 |
# Set output size based on selection
|
37 |
-
image_size = (
|
38 |
|
39 |
# Generate image with specified quality and size
|
40 |
with torch.no_grad():
|
@@ -52,14 +52,14 @@ def adjust_brightness_contrast(image, brightness, contrast):
|
|
52 |
|
53 |
# Warning function to show a message if the user selects a high value for quality
|
54 |
def show_warning(quality):
|
55 |
-
if quality >
|
56 |
-
return "⚠️ High Quality: This setting may slow down generation
|
57 |
return ""
|
58 |
|
59 |
# Build Gradio Interface
|
60 |
with gr.Blocks() as demo:
|
61 |
gr.Markdown("# ✨ AI-Powered Wallpaper/Profile Picture Generator\n🖼️ A tool to generate and fine-tune AI-created wallpapers and profile pictures with adjustable styles and effects.")
|
62 |
-
gr.Markdown("⚠️ **Live effects and advanced prompt engineering coming soon
|
63 |
|
64 |
# Image Generation Section
|
65 |
with gr.Tab("Image Generator"):
|
@@ -79,18 +79,18 @@ with gr.Blocks() as demo:
|
|
79 |
theme = gr.Dropdown(["Landscape", "Portrait", "Abstract Patterns", "Architecture"], label="Theme")
|
80 |
lighting = gr.Dropdown(["Warm", "Cool", "Cinematic", "Soft", "Neon"], label="Lighting")
|
81 |
|
82 |
-
quality = gr.Slider(
|
83 |
warning_message = gr.Markdown("")
|
84 |
|
85 |
# Scheduler selection with default option
|
86 |
scheduler_choice = gr.Dropdown(
|
87 |
[
|
|
|
88 |
"Artistic & Imaginative (Euler Ancestral) - Recommended for creative scenes, moderate speed",
|
89 |
-
"Photo-Realistic (PNDM) - Best for realistic details, moderate speed"
|
90 |
-
"High-Definition & Fast (DDIM) - Good quality with fastest speed"
|
91 |
],
|
92 |
label="Artistic Style & Speed",
|
93 |
-
value="
|
94 |
)
|
95 |
|
96 |
size = gr.Dropdown(["Profile Picture", "Wallpaper"], label="Image Size", value="Profile Picture")
|
|
|
6 |
|
7 |
# Load Stable Diffusion pipeline
|
8 |
model_id = "CompVis/stable-diffusion-v1-4"
|
9 |
+
default_scheduler = DDIMScheduler.from_pretrained(model_id, subfolder="scheduler")
|
10 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=default_scheduler, torch_dtype=torch.float32, low_cpu_mem_usage=True)
|
11 |
+
pipe = pipe.to("cpu") # Use CPU
|
12 |
|
13 |
# Scheduler options
|
14 |
schedulers = {
|
15 |
+
"High-Definition & Fast (DDIM) - Good quality with fastest speed": DDIMScheduler,
|
16 |
"Artistic & Imaginative (Euler Ancestral) - Recommended for creative scenes, moderate speed": EulerAncestralDiscreteScheduler,
|
17 |
"Photo-Realistic (PNDM) - Best for realistic details, moderate speed": PNDMScheduler,
|
|
|
18 |
}
|
19 |
|
20 |
# Main image generation function with dynamic scheduling and size option
|
|
|
34 |
pipe.scheduler = scheduler
|
35 |
|
36 |
# Set output size based on selection
|
37 |
+
image_size = (256, 256) if size == "Profile Picture" else (384, 384)
|
38 |
|
39 |
# Generate image with specified quality and size
|
40 |
with torch.no_grad():
|
|
|
52 |
|
53 |
# Warning function to show a message if the user selects a high value for quality
|
54 |
def show_warning(quality):
|
55 |
+
if quality > 30:
|
56 |
+
return "⚠️ High Quality: This setting may slow down generation. Consider using 10-30 steps for best results."
|
57 |
return ""
|
58 |
|
59 |
# Build Gradio Interface
|
60 |
with gr.Blocks() as demo:
|
61 |
gr.Markdown("# ✨ AI-Powered Wallpaper/Profile Picture Generator\n🖼️ A tool to generate and fine-tune AI-created wallpapers and profile pictures with adjustable styles and effects.")
|
62 |
+
gr.Markdown("⚠️ **Live effects and advanced prompt engineering coming soon!** Results may vary, so try experimenting with settings to achieve the best results.")
|
63 |
|
64 |
# Image Generation Section
|
65 |
with gr.Tab("Image Generator"):
|
|
|
79 |
theme = gr.Dropdown(["Landscape", "Portrait", "Abstract Patterns", "Architecture"], label="Theme")
|
80 |
lighting = gr.Dropdown(["Warm", "Cool", "Cinematic", "Soft", "Neon"], label="Lighting")
|
81 |
|
82 |
+
quality = gr.Slider(10, 30, value=20, step=5, label="Image Quality", info="Higher values yield more detail but take longer to generate.")
|
83 |
warning_message = gr.Markdown("")
|
84 |
|
85 |
# Scheduler selection with default option
|
86 |
scheduler_choice = gr.Dropdown(
|
87 |
[
|
88 |
+
"High-Definition & Fast (DDIM) - Good quality with fastest speed",
|
89 |
"Artistic & Imaginative (Euler Ancestral) - Recommended for creative scenes, moderate speed",
|
90 |
+
"Photo-Realistic (PNDM) - Best for realistic details, moderate speed"
|
|
|
91 |
],
|
92 |
label="Artistic Style & Speed",
|
93 |
+
value="High-Definition & Fast (DDIM) - Good quality with fastest speed"
|
94 |
)
|
95 |
|
96 |
size = gr.Dropdown(["Profile Picture", "Wallpaper"], label="Image Size", value="Profile Picture")
|