Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,10 @@ import time
|
|
16 |
import os
|
17 |
from ip_adapter import IPAdapterXL
|
18 |
from image_gen_aux import UpscaleWithModel
|
19 |
-
from huggingface_hub import
|
|
|
|
|
|
|
20 |
|
21 |
FTP_HOST = "1ink.us"
|
22 |
FTP_USER = "ford442"
|
@@ -35,6 +38,9 @@ torch.set_float32_matmul_precision("highest")
|
|
35 |
|
36 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
37 |
|
|
|
|
|
|
|
38 |
def upload_to_ftp(filename):
|
39 |
try:
|
40 |
transport = paramiko.Transport((FTP_HOST, 22))
|
@@ -57,7 +63,13 @@ checkpoint = "microsoft/Phi-3.5-mini-instruct"
|
|
57 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
58 |
#vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(torch.device("cuda:0"))
|
62 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/RealVis_Medium_1.0b_bf16", torch_dtype=torch.bfloat16)
|
63 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
@@ -89,26 +101,14 @@ model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map='balanced')
|
|
89 |
|
90 |
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
local_repo_path = snapshot_download(repo_id=repo_id, repo_type="model")
|
98 |
|
99 |
-
# Construct the paths to the subfolders
|
100 |
-
local_folder = os.path.join(local_repo_path, subfolder)
|
101 |
-
local_folder2 = os.path.join(local_repo_path, subfolder2) # Path to the ip_adapter dir
|
102 |
|
103 |
-
print(f"Image encoder downloaded to: {local_folder}")
|
104 |
-
print(f"IP Adapter files downloaded to: {local_folder2}")
|
105 |
|
106 |
-
# Construct the path to the ip-adapter_sdxl.bin file
|
107 |
-
#ip_ckpt = os.path.join(local_folder2, "ip-adapter_sdxl.bin") # Correct path
|
108 |
-
ip_ckpt = os.path.join(local_folder2, "ip-adapter_sdxl_vit-h.bin") # Correct path
|
109 |
-
|
110 |
-
print(f"IP Adapter checkpoint path: {ip_ckpt}")
|
111 |
-
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
112 |
|
113 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
114 |
|
@@ -221,14 +221,14 @@ def infer(
|
|
221 |
print("-- using image file --")
|
222 |
print('-- generating image --')
|
223 |
#with torch.no_grad():
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
)
|
232 |
rv_path = f"sd35_{seed}.png"
|
233 |
sd_image[0].save(rv_path,optimize=False,compress_level=0)
|
234 |
upload_to_ftp(rv_path)
|
|
|
16 |
import os
|
17 |
from ip_adapter import IPAdapterXL
|
18 |
from image_gen_aux import UpscaleWithModel
|
19 |
+
from huggingface_hub import hf_hub_download
|
20 |
+
from models.transformer_sd3 import SD3Transformer2DModel
|
21 |
+
from pipeline_stable_diffusion_3_ipa import StableDiffusion3Pipeline
|
22 |
+
from PIL import Image
|
23 |
|
24 |
FTP_HOST = "1ink.us"
|
25 |
FTP_USER = "ford442"
|
|
|
38 |
|
39 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
40 |
|
41 |
+
image_encoder_path = "google/siglip-so400m-patch14-384"
|
42 |
+
ipadapter_path = hf_hub_download(repo_id="InstantX/SD3.5-Large-IP-Adapter", filename="ip-adapter.bin")
|
43 |
+
|
44 |
def upload_to_ftp(filename):
|
45 |
try:
|
46 |
transport = paramiko.Transport((FTP_HOST, 22))
|
|
|
63 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
64 |
#vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
65 |
|
66 |
+
transformer = SD3Transformer2DModel.from_pretrained(
|
67 |
+
model_path,
|
68 |
+
subfolder="transformer",
|
69 |
+
torch_dtype=torch.bfloat16
|
70 |
+
)
|
71 |
+
|
72 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16", transformer=transformer).to(device=torch.device("cuda:0"), dtype=torch.bfloat16)
|
73 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(torch.device("cuda:0"))
|
74 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/RealVis_Medium_1.0b_bf16", torch_dtype=torch.bfloat16)
|
75 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
|
|
101 |
|
102 |
|
103 |
|
104 |
+
pipe.init_ipadapter(
|
105 |
+
ip_adapter_path=ipadapter_path,
|
106 |
+
image_encoder_path=image_encoder_path,
|
107 |
+
nb_token=64,
|
108 |
+
)
|
|
|
109 |
|
|
|
|
|
|
|
110 |
|
|
|
|
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
114 |
|
|
|
221 |
print("-- using image file --")
|
222 |
print('-- generating image --')
|
223 |
#with torch.no_grad():
|
224 |
+
result = pipe(
|
225 |
+
clip_image=image,
|
226 |
+
prompt=prompt,
|
227 |
+
ipadapter_scale=scale,
|
228 |
+
width=width,
|
229 |
+
height=height,
|
230 |
+
generator=torch.Generator().manual_seed(seed)
|
231 |
+
).images[0]
|
232 |
rv_path = f"sd35_{seed}.png"
|
233 |
sd_image[0].save(rv_path,optimize=False,compress_level=0)
|
234 |
upload_to_ftp(rv_path)
|