Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +12 -38
- requirements.txt +0 -2
app.py
CHANGED
|
@@ -1,28 +1,26 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
-
from diffusers import
|
| 5 |
import warnings
|
| 6 |
warnings.filterwarnings('ignore')
|
| 7 |
|
| 8 |
# Constants
|
| 9 |
-
MODEL_ID = "google/ddpm-celebahq-256"
|
| 10 |
DEVICE = "cpu" # Force CPU for better compatibility
|
| 11 |
DTYPE = torch.float32
|
| 12 |
|
| 13 |
-
def generate_image(
|
| 14 |
try:
|
| 15 |
# Initialize pipeline with basic settings
|
| 16 |
-
pipe =
|
| 17 |
pipe = pipe.to(DEVICE)
|
| 18 |
|
| 19 |
# Generate image
|
| 20 |
with torch.inference_mode():
|
| 21 |
image = pipe(
|
| 22 |
-
|
| 23 |
-
negative_prompt=negative_prompt,
|
| 24 |
num_inference_steps=steps,
|
| 25 |
-
guidance_scale=guidance_scale,
|
| 26 |
).images[0]
|
| 27 |
|
| 28 |
return image
|
|
@@ -33,38 +31,17 @@ def generate_image(prompt, negative_prompt, guidance_scale=7.5, steps=30):
|
|
| 33 |
# Create the Gradio interface
|
| 34 |
with gr.Blocks(title="Simple Image Generator") as demo:
|
| 35 |
gr.Markdown("# 🎨 Simple Image Generator")
|
| 36 |
-
gr.Markdown("Generate
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column():
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
)
|
| 45 |
-
negative_prompt = gr.Textbox(
|
| 46 |
-
label="Negative Prompt",
|
| 47 |
-
placeholder="What you don't want in the image...",
|
| 48 |
-
info="Specify unwanted elements",
|
| 49 |
-
value="ugly, blurry, low quality"
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
with gr.Row():
|
| 53 |
-
steps = gr.Slider(
|
| 54 |
-
minimum=10,
|
| 55 |
-
maximum=50,
|
| 56 |
-
value=30,
|
| 57 |
-
step=1,
|
| 58 |
-
label="Steps"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
guidance_scale = gr.Slider(
|
| 62 |
-
minimum=1.0,
|
| 63 |
-
maximum=20.0,
|
| 64 |
-
value=7.5,
|
| 65 |
-
step=0.1,
|
| 66 |
-
label="Guidance Scale"
|
| 67 |
-
)
|
| 68 |
|
| 69 |
generate_btn = gr.Button("🎨 Generate", variant="primary")
|
| 70 |
|
|
@@ -74,9 +51,6 @@ with gr.Blocks(title="Simple Image Generator") as demo:
|
|
| 74 |
generate_btn.click(
|
| 75 |
fn=generate_image,
|
| 76 |
inputs=[
|
| 77 |
-
prompt,
|
| 78 |
-
negative_prompt,
|
| 79 |
-
guidance_scale,
|
| 80 |
steps,
|
| 81 |
],
|
| 82 |
outputs=output_image
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
+
from diffusers import DDPMPipeline
|
| 5 |
import warnings
|
| 6 |
warnings.filterwarnings('ignore')
|
| 7 |
|
| 8 |
# Constants
|
| 9 |
+
MODEL_ID = "google/ddpm-celebahq-256"
|
| 10 |
DEVICE = "cpu" # Force CPU for better compatibility
|
| 11 |
DTYPE = torch.float32
|
| 12 |
|
| 13 |
+
def generate_image(steps=30):
|
| 14 |
try:
|
| 15 |
# Initialize pipeline with basic settings
|
| 16 |
+
pipe = DDPMPipeline.from_pretrained(MODEL_ID)
|
| 17 |
pipe = pipe.to(DEVICE)
|
| 18 |
|
| 19 |
# Generate image
|
| 20 |
with torch.inference_mode():
|
| 21 |
image = pipe(
|
| 22 |
+
batch_size=1,
|
|
|
|
| 23 |
num_inference_steps=steps,
|
|
|
|
| 24 |
).images[0]
|
| 25 |
|
| 26 |
return image
|
|
|
|
| 31 |
# Create the Gradio interface
|
| 32 |
with gr.Blocks(title="Simple Image Generator") as demo:
|
| 33 |
gr.Markdown("# 🎨 Simple Image Generator")
|
| 34 |
+
gr.Markdown("Generate celebrity-like faces using DDPM")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
with gr.Column():
|
| 38 |
+
steps = gr.Slider(
|
| 39 |
+
minimum=10,
|
| 40 |
+
maximum=50,
|
| 41 |
+
value=30,
|
| 42 |
+
step=1,
|
| 43 |
+
label="Steps"
|
| 44 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
generate_btn = gr.Button("🎨 Generate", variant="primary")
|
| 47 |
|
|
|
|
| 51 |
generate_btn.click(
|
| 52 |
fn=generate_image,
|
| 53 |
inputs=[
|
|
|
|
|
|
|
|
|
|
| 54 |
steps,
|
| 55 |
],
|
| 56 |
outputs=output_image
|
requirements.txt
CHANGED
|
@@ -4,5 +4,3 @@ diffusers==0.2.4
|
|
| 4 |
transformers==4.18.0
|
| 5 |
accelerate==0.12.0
|
| 6 |
gradio==3.16.2
|
| 7 |
-
opencv-python==4.8.0.74
|
| 8 |
-
einops==0.6.1
|
|
|
|
| 4 |
transformers==4.18.0
|
| 5 |
accelerate==0.12.0
|
| 6 |
gradio==3.16.2
|
|
|
|
|
|