Spaces:
Paused
Paused
Update app.py
Browse filesadding blip and negative prompt
app.py
CHANGED
@@ -8,19 +8,23 @@ import numpy as np
|
|
8 |
import cv2
|
9 |
|
10 |
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel
|
11 |
-
from utils.planner import
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# ----------------------------
|
14 |
# π§ Device Setup
|
15 |
# ----------------------------
|
16 |
-
device = "cpu"
|
17 |
dtype = torch.float32
|
18 |
|
19 |
# ----------------------------
|
20 |
-
# β
Load ControlNet + SDXL Model
|
21 |
# ----------------------------
|
22 |
controlnet = ControlNetModel.from_pretrained(
|
23 |
-
"diffusers/controlnet-canny-sdxl-1.0",
|
24 |
torch_dtype=dtype
|
25 |
)
|
26 |
|
@@ -54,30 +58,35 @@ def generate_canny_map(image: Image.Image) -> Image.Image:
|
|
54 |
def process_image(prompt, image, num_variations):
|
55 |
try:
|
56 |
print("π§ Prompt received:", prompt)
|
57 |
-
|
58 |
if image is None:
|
59 |
raise ValueError("π« Uploaded image is missing or invalid.")
|
60 |
|
61 |
-
# Step 1:
|
62 |
-
scene_plan = extract_scene_plan(prompt)
|
63 |
print("π§ Scene plan extracted:", scene_plan)
|
64 |
|
65 |
-
# Step 2:
|
66 |
prompt_list = generate_prompt_variations_from_scene(scene_plan, prompt, num_variations)
|
67 |
print("π§ Enriched Prompts:")
|
68 |
for i, p in enumerate(prompt_list):
|
69 |
print(f" {i+1}: {p}")
|
70 |
|
71 |
-
# Step 3:
|
|
|
|
|
|
|
|
|
72 |
image = image.resize((1024, 1024)).convert("RGB")
|
73 |
canny_map = generate_canny_map(image)
|
74 |
|
|
|
75 |
outputs = []
|
76 |
for i, enriched_prompt in enumerate(prompt_list):
|
77 |
print(f"π¨ Generating image {i+1}...")
|
78 |
try:
|
79 |
result = pipe(
|
80 |
prompt=enriched_prompt,
|
|
|
81 |
image=image,
|
82 |
control_image=canny_map,
|
83 |
num_inference_steps=30,
|
@@ -99,7 +108,7 @@ def process_image(prompt, image, num_variations):
|
|
99 |
# πΌ Gradio UI
|
100 |
# ----------------------------
|
101 |
with gr.Blocks() as demo:
|
102 |
-
gr.Markdown("## π§ NewCrux AI β SDXL + Canny (CPU Mode)\nUpload a product image, enter a prompt, and generate enhanced visuals
|
103 |
|
104 |
with gr.Row():
|
105 |
with gr.Column():
|
@@ -120,4 +129,3 @@ with gr.Blocks() as demo:
|
|
120 |
)
|
121 |
|
122 |
demo.launch()
|
123 |
-
|
|
|
8 |
import cv2
|
9 |
|
10 |
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel
|
11 |
+
from utils.planner import (
|
12 |
+
extract_scene_plan,
|
13 |
+
generate_prompt_variations_from_scene,
|
14 |
+
generate_negative_prompt_from_scene # β
Added negative prompt generator
|
15 |
+
)
|
16 |
|
17 |
# ----------------------------
|
18 |
# π§ Device Setup
|
19 |
# ----------------------------
|
20 |
+
device = "cpu"
|
21 |
dtype = torch.float32
|
22 |
|
23 |
# ----------------------------
|
24 |
+
# β
Load ControlNet + SDXL Model
|
25 |
# ----------------------------
|
26 |
controlnet = ControlNetModel.from_pretrained(
|
27 |
+
"diffusers/controlnet-canny-sdxl-1.0",
|
28 |
torch_dtype=dtype
|
29 |
)
|
30 |
|
|
|
58 |
def process_image(prompt, image, num_variations):
|
59 |
try:
|
60 |
print("π§ Prompt received:", prompt)
|
|
|
61 |
if image is None:
|
62 |
raise ValueError("π« Uploaded image is missing or invalid.")
|
63 |
|
64 |
+
# Step 1: Scene Planning
|
65 |
+
scene_plan = extract_scene_plan(prompt, image)
|
66 |
print("π§ Scene plan extracted:", scene_plan)
|
67 |
|
68 |
+
# Step 2: Prompt Variations
|
69 |
prompt_list = generate_prompt_variations_from_scene(scene_plan, prompt, num_variations)
|
70 |
print("π§ Enriched Prompts:")
|
71 |
for i, p in enumerate(prompt_list):
|
72 |
print(f" {i+1}: {p}")
|
73 |
|
74 |
+
# Step 3: Negative Prompt (auto-generated)
|
75 |
+
negative_prompt = generate_negative_prompt_from_scene(scene_plan)
|
76 |
+
print("π« Negative Prompt:", negative_prompt)
|
77 |
+
|
78 |
+
# Step 4: Prepare image & canny
|
79 |
image = image.resize((1024, 1024)).convert("RGB")
|
80 |
canny_map = generate_canny_map(image)
|
81 |
|
82 |
+
# Step 5: Generate images
|
83 |
outputs = []
|
84 |
for i, enriched_prompt in enumerate(prompt_list):
|
85 |
print(f"π¨ Generating image {i+1}...")
|
86 |
try:
|
87 |
result = pipe(
|
88 |
prompt=enriched_prompt,
|
89 |
+
negative_prompt=negative_prompt,
|
90 |
image=image,
|
91 |
control_image=canny_map,
|
92 |
num_inference_steps=30,
|
|
|
108 |
# πΌ Gradio UI
|
109 |
# ----------------------------
|
110 |
with gr.Blocks() as demo:
|
111 |
+
gr.Markdown("## π§ NewCrux AI β SDXL + ControlNet Canny (CPU Mode)\nUpload a product image, enter a prompt, and generate enhanced visuals with GPT + BLIP + SDXL.")
|
112 |
|
113 |
with gr.Row():
|
114 |
with gr.Column():
|
|
|
129 |
)
|
130 |
|
131 |
demo.launch()
|
|