Spaces:
Running on Zero
Running on Zero
Update app_v4.py
Browse files
app_v4.py
CHANGED
|
@@ -67,33 +67,6 @@ def resize_image_to_max_side(image: Image, max_side_length=1024) -> Image:
|
|
| 67 |
resized_image = image.resize(new_size, Image.BILINEAR)
|
| 68 |
return resized_image
|
| 69 |
|
| 70 |
-
@spaces.GPU(duration=6, progress=gr.Progress(track_tqdm=True))
|
| 71 |
-
@torch.no_grad()
|
| 72 |
-
def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_scale, guidance_scale, seed, guidance_end):
|
| 73 |
-
generator = torch.Generator().manual_seed(seed)
|
| 74 |
-
# Load control image
|
| 75 |
-
control_image = load_image(control_image)
|
| 76 |
-
w, h = control_image.size
|
| 77 |
-
w = w - w % 32
|
| 78 |
-
h = h - h % 32
|
| 79 |
-
control_image = control_image.resize((int(w * scale), int(h * scale)), resample=2) # Resample.BILINEAR
|
| 80 |
-
print("Size to: " + str(control_image.size[0]) + ", " + str(control_image.size[1]))
|
| 81 |
-
print(f"PromptLog: {repr(prompt)}")
|
| 82 |
-
with torch.inference_mode():
|
| 83 |
-
image = pipe(
|
| 84 |
-
generator=generator,
|
| 85 |
-
prompt=prompt,
|
| 86 |
-
control_image=control_image,
|
| 87 |
-
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 88 |
-
num_inference_steps=steps,
|
| 89 |
-
guidance_scale=guidance_scale,
|
| 90 |
-
height=control_image.size[1],
|
| 91 |
-
width=control_image.size[0],
|
| 92 |
-
control_guidance_start=0.0,
|
| 93 |
-
control_guidance_end=guidance_end,
|
| 94 |
-
).images[0]
|
| 95 |
-
# print("Type: " + str(type(image)))
|
| 96 |
-
return image
|
| 97 |
|
| 98 |
def combine_caption_focus(caption, focus):
|
| 99 |
try:
|
|
@@ -173,11 +146,10 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 173 |
).images[0]
|
| 174 |
# print("Type: " + str(type(image)))
|
| 175 |
return image
|
| 176 |
-
progress = gr.Progress(track_tqdm=True)
|
| 177 |
|
| 178 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 179 |
controlnet_conditioning_scale, guidance_scale, seed,
|
| 180 |
-
guidance_end, temperature, top_p, max_new_tokens, log_prompt, progress):
|
| 181 |
# Initialize with empty caption
|
| 182 |
final_prompt = user_prompt.strip()
|
| 183 |
# If no user prompt provided, generate a caption first
|
|
|
|
| 67 |
resized_image = image.resize(new_size, Image.BILINEAR)
|
| 68 |
return resized_image
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
def combine_caption_focus(caption, focus):
|
| 72 |
try:
|
|
|
|
| 146 |
).images[0]
|
| 147 |
# print("Type: " + str(type(image)))
|
| 148 |
return image
|
|
|
|
| 149 |
|
| 150 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 151 |
controlnet_conditioning_scale, guidance_scale, seed,
|
| 152 |
+
guidance_end, temperature, top_p, max_new_tokens, log_prompt, progress = gr.Progress(track_tqdm=True)):
|
| 153 |
# Initialize with empty caption
|
| 154 |
final_prompt = user_prompt.strip()
|
| 155 |
# If no user prompt provided, generate a caption first
|