Quiho commited on
Commit
f15963e
·
verified ·
1 Parent(s): b980f68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -10,20 +10,20 @@ def convert_embedding(uploaded_files):
10
  output_files = []
11
 
12
  for uploaded_file in uploaded_files:
13
- file_name, file_extension = os.path.splitext(uploaded_file.name)
14
  output_path = f"{file_name}_XL.safetensors"
15
 
16
  if file_extension == '.pt':
17
- sd15_embedding = torch.load(uploaded_file.name, map_location=torch.device('cpu'))
18
  sd15_tensor = sd15_embedding.get('string_to_param', {}).get('*')
19
  elif file_extension == '.safetensors':
20
- loaded_tensors = load_file(uploaded_file.name)
21
  sd15_tensor = loaded_tensors.get('emb_params')
22
  else:
23
  raise ValueError(f"Unsupported file format: {file_extension}")
24
 
25
  if sd15_tensor is None:
26
- raise ValueError(f"Invalid embedding structure in file: {uploaded_file.name}")
27
 
28
  num_vectors = sd15_tensor.shape[0]
29
  clip_g_shape = (num_vectors, 1280)
@@ -72,7 +72,7 @@ custom_css = """
72
 
73
  iface = gr.Interface(
74
  fn=convert_embedding,
75
- inputs=gr.Files(label="Upload SD-1.5 embeddings (Max 5)", type="file"),
76
  outputs=gr.Files(label="Download converted SDXL safetensors embeddings"),
77
  title="✨ SD-1.5 to SDXL Embedding Converter | Now supports multiple files ⚡",
78
  description="Upload up to 5 SD-1.5 embedding files to convert them to SDXL. Stylish and efficient!",
 
10
  output_files = []
11
 
12
  for uploaded_file in uploaded_files:
13
+ file_name, file_extension = os.path.splitext(os.path.basename(uploaded_file))
14
  output_path = f"{file_name}_XL.safetensors"
15
 
16
  if file_extension == '.pt':
17
+ sd15_embedding = torch.load(uploaded_file, map_location=torch.device('cpu'))
18
  sd15_tensor = sd15_embedding.get('string_to_param', {}).get('*')
19
  elif file_extension == '.safetensors':
20
+ loaded_tensors = load_file(uploaded_file)
21
  sd15_tensor = loaded_tensors.get('emb_params')
22
  else:
23
  raise ValueError(f"Unsupported file format: {file_extension}")
24
 
25
  if sd15_tensor is None:
26
+ raise ValueError(f"Invalid embedding structure in file: {uploaded_file}")
27
 
28
  num_vectors = sd15_tensor.shape[0]
29
  clip_g_shape = (num_vectors, 1280)
 
72
 
73
  iface = gr.Interface(
74
  fn=convert_embedding,
75
+ inputs=gr.Files(label="Upload SD-1.5 embeddings (Max 5)", type="filepath"),
76
  outputs=gr.Files(label="Download converted SDXL safetensors embeddings"),
77
  title="✨ SD-1.5 to SDXL Embedding Converter | Now supports multiple files ⚡",
78
  description="Upload up to 5 SD-1.5 embedding files to convert them to SDXL. Stylish and efficient!",