Update app.py
Browse files
app.py
CHANGED
|
@@ -6,52 +6,24 @@ import os
|
|
| 6 |
def convert_embedding(sd15_embedding):
|
| 7 |
output_path = "embedding.safetensors"
|
| 8 |
|
| 9 |
-
print("got here 1")
|
| 10 |
-
|
| 11 |
sd15_embedding = torch.load(sd15_embedding.name, map_location=torch.device('cpu'), weights_only=True)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
print("got here 2")
|
| 15 |
-
|
| 16 |
-
|
| 17 |
sd15_tensor = sd15_embedding['string_to_param']['*']
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
print("got here 3")
|
| 21 |
-
|
| 22 |
|
| 23 |
num_vectors = sd15_tensor.shape[0]
|
| 24 |
clip_g_shape = (num_vectors, 1280)
|
| 25 |
clip_l_shape = (num_vectors, 768)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
print("got here 4")
|
| 30 |
-
|
| 31 |
-
|
| 32 |
clip_g = torch.zeros(clip_g_shape, dtype=torch.float16)
|
| 33 |
clip_l = torch.zeros(clip_l_shape, dtype=torch.float16)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
print("got here 5")
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
clip_l[:sd15_tensor.shape[0], :sd15_tensor.shape[1]] = sd15_tensor.to(dtype=torch.float16)
|
| 43 |
save_file({"clip_g": clip_g, "clip_l": clip_l}, output_path)
|
| 44 |
|
| 45 |
-
print("got here 6")
|
| 46 |
-
|
| 47 |
-
|
| 48 |
# Return the path to the converted file for download
|
| 49 |
return output_path
|
| 50 |
|
| 51 |
iface = gr.Interface(
|
| 52 |
fn=convert_embedding,
|
| 53 |
-
inputs=gr.File(label="Upload SD1.5 pt
|
| 54 |
-
outputs=gr.File(label="Download
|
| 55 |
title="SD1.5 to SDXL Embedding Converter",
|
| 56 |
description="Upload an SD1.5 embedding file in pt format to convert it to SDXL."
|
| 57 |
)
|
|
|
|
| 6 |
def convert_embedding(sd15_embedding):
|
| 7 |
output_path = "embedding.safetensors"
|
| 8 |
|
|
|
|
|
|
|
| 9 |
sd15_embedding = torch.load(sd15_embedding.name, map_location=torch.device('cpu'), weights_only=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
sd15_tensor = sd15_embedding['string_to_param']['*']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
num_vectors = sd15_tensor.shape[0]
|
| 13 |
clip_g_shape = (num_vectors, 1280)
|
| 14 |
clip_l_shape = (num_vectors, 768)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
clip_g = torch.zeros(clip_g_shape, dtype=torch.float16)
|
| 16 |
clip_l = torch.zeros(clip_l_shape, dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
clip_l[:sd15_tensor.shape[0], :sd15_tensor.shape[1]] = sd15_tensor.to(dtype=torch.float16)
|
| 18 |
save_file({"clip_g": clip_g, "clip_l": clip_l}, output_path)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# Return the path to the converted file for download
|
| 21 |
return output_path
|
| 22 |
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=convert_embedding,
|
| 25 |
+
inputs=gr.File(label="Upload SD1.5 pt embedding"),
|
| 26 |
+
outputs=gr.File(label="Download converted SDXL safetensors embedding"),
|
| 27 |
title="SD1.5 to SDXL Embedding Converter",
|
| 28 |
description="Upload an SD1.5 embedding file in pt format to convert it to SDXL."
|
| 29 |
)
|