Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,9 @@ import paramiko
|
|
| 14 |
import urllib
|
| 15 |
import time
|
| 16 |
import os
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
FTP_HOST = "1ink.us"
|
| 19 |
FTP_USER = "ford442"
|
|
@@ -48,6 +51,31 @@ def upload_to_ftp(filename):
|
|
| 48 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 49 |
torch_dtype = torch.bfloat16
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
checkpoint = "microsoft/Phi-3.5-mini-instruct"
|
| 52 |
#vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 53 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
|
@@ -186,23 +214,18 @@ def infer(
|
|
| 186 |
# device=pipe.device,
|
| 187 |
# generator=generator,
|
| 188 |
# )
|
| 189 |
-
sd_image_a =
|
| 190 |
-
|
| 191 |
-
#sd_image_b = pipe.vae.encode(sd_image_a.to(torch.bfloat16)).latent_dist.sample().mul_(0.18215)
|
| 192 |
-
print("-- using latent file --")
|
| 193 |
print('-- generating image --')
|
| 194 |
#with torch.no_grad():
|
| 195 |
-
sd_image =
|
| 196 |
-
prompt=enhanced_prompt,
|
| 197 |
-
|
| 198 |
-
|
| 199 |
num_inference_steps=num_inference_steps,
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
# output='latent',
|
| 204 |
-
generator=generator
|
| 205 |
-
).images[0]
|
| 206 |
rv_path = f"sd35_{seed}.png"
|
| 207 |
sd_image[0].save(rv_path,optimize=False,compress_level=0)
|
| 208 |
upload_to_ftp(rv_path)
|
|
@@ -329,7 +352,7 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 329 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 330 |
result = gr.Image(label="Result", show_label=False)
|
| 331 |
with gr.Accordion("Advanced Settings", open=False):
|
| 332 |
-
latent_file = gr.File(label="
|
| 333 |
negative_prompt = gr.Text(
|
| 334 |
label="Negative prompt",
|
| 335 |
max_lines=1,
|
|
|
|
| 14 |
import urllib
|
| 15 |
import time
|
| 16 |
import os
|
| 17 |
+
from ip_adapter import IPAdapterXL
|
| 18 |
+
from image_gen_aux import UpscaleWithModel
|
| 19 |
+
from huggingface_hub import snapshot_download
|
| 20 |
|
| 21 |
FTP_HOST = "1ink.us"
|
| 22 |
FTP_USER = "ford442"
|
|
|
|
| 51 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 52 |
torch_dtype = torch.bfloat16
|
| 53 |
|
| 54 |
+
|
| 55 |
+
repo_id = "ford442/SDXL-IP_ADAPTER"
|
| 56 |
+
subfolder = "image_encoder"
|
| 57 |
+
subfolder2 = "ip_adapter"
|
| 58 |
+
|
| 59 |
+
# Download the entire repository
|
| 60 |
+
local_repo_path = snapshot_download(repo_id=repo_id, repo_type="model")
|
| 61 |
+
|
| 62 |
+
# Construct the paths to the subfolders
|
| 63 |
+
local_folder = os.path.join(local_repo_path, subfolder)
|
| 64 |
+
local_folder2 = os.path.join(local_repo_path, subfolder2) # Path to the ip_adapter dir
|
| 65 |
+
|
| 66 |
+
print(f"Image encoder downloaded to: {local_folder}")
|
| 67 |
+
print(f"IP Adapter files downloaded to: {local_folder2}")
|
| 68 |
+
|
| 69 |
+
# Construct the path to the ip-adapter_sdxl.bin file
|
| 70 |
+
#ip_ckpt = os.path.join(local_folder2, "ip-adapter_sdxl.bin") # Correct path
|
| 71 |
+
ip_ckpt = os.path.join(local_folder2, "ip-adapter_sdxl_vit-h.bin") # Correct path
|
| 72 |
+
|
| 73 |
+
print(f"IP Adapter checkpoint path: {ip_ckpt}")
|
| 74 |
+
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 75 |
+
|
| 76 |
+
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
| 77 |
+
|
| 78 |
+
|
| 79 |
checkpoint = "microsoft/Phi-3.5-mini-instruct"
|
| 80 |
#vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 81 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
|
|
|
| 214 |
# device=pipe.device,
|
| 215 |
# generator=generator,
|
| 216 |
# )
|
| 217 |
+
sd_image_a = Image.open(latent_file.name)
|
| 218 |
+
print("-- using image file --")
|
|
|
|
|
|
|
| 219 |
print('-- generating image --')
|
| 220 |
#with torch.no_grad():
|
| 221 |
+
sd_image = ip_model.generate(
|
| 222 |
+
prompt=enhanced_prompt,
|
| 223 |
+
pil_image=sd_image_a,
|
| 224 |
+
num_samples=1,
|
| 225 |
num_inference_steps=num_inference_steps,
|
| 226 |
+
guidance_scale=guidance_scale,
|
| 227 |
+
seed=seed
|
| 228 |
+
)
|
|
|
|
|
|
|
|
|
|
| 229 |
rv_path = f"sd35_{seed}.png"
|
| 230 |
sd_image[0].save(rv_path,optimize=False,compress_level=0)
|
| 231 |
upload_to_ftp(rv_path)
|
|
|
|
| 352 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 353 |
result = gr.Image(label="Result", show_label=False)
|
| 354 |
with gr.Accordion("Advanced Settings", open=False):
|
| 355 |
+
latent_file = gr.File(label="Image File (optional)") # Add latents file input
|
| 356 |
negative_prompt = gr.Text(
|
| 357 |
label="Negative prompt",
|
| 358 |
max_lines=1,
|