rootlocalghost commited on
Commit
c85e14f
Β·
verified Β·
1 Parent(s): 81541ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -8,13 +8,16 @@ from safetensors.torch import load_file, save_file
8
 
9
  TEMP_DIR = "temp_processing_dir"
10
 
11
- def convert_and_upload(token, source_repo, target_repo, precision):
12
  if not token:
13
  yield "❌ Error: Please provide a valid Hugging Face Write Token."
14
  return
15
  if not target_repo.strip() or "your-username" in target_repo:
16
  yield "❌ Error: Please specify a valid Target Repository (e.g., your-username/repo-name)."
17
  return
 
 
 
18
 
19
  # Map precision string to PyTorch dtype
20
  if precision == "FP8":
@@ -56,8 +59,11 @@ def convert_and_upload(token, source_repo, target_repo, precision):
56
  local_dir_use_symlinks=False
57
  )
58
 
59
- # Check if it's a target safetensor file
60
- if file.endswith(".safetensors") and ("text_encoder/" in file or "transformer/" in file):
 
 
 
61
  yield f"🧠 Quantizing {file} to {precision}..."
62
 
63
  tensors = load_file(local_path)
@@ -120,7 +126,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
120
  gr.Markdown("# πŸš€ Z-Image Quantizer & Uploader")
121
  gr.Markdown(
122
  "Convert the **Z-Image** or **Z-Image-Turbo** models to lower precisions (FP8, FP16, BF16) and push them directly to your own Hugging Face account.\n\n"
123
- "**How it works:** This tool sequentially downloads, quantizes the **text_encoder** and **transformer** files, and uploads everything. "
124
  "It is designed to run safely on free Spaces (16GB RAM) by processing files one at a time."
125
  )
126
 
@@ -140,6 +146,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
140
  value="Tongyi-MAI/Z-Image-Turbo",
141
  label="Source Repository"
142
  )
 
 
 
 
 
 
 
 
 
143
  precision = gr.Dropdown(
144
  choices=["FP8", "FP16", "BF16"],
145
  value="FP8",
@@ -171,7 +186,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
171
 
172
  start_btn.click(
173
  fn=convert_and_upload,
174
- inputs=[hf_token, source_repo, target_repo, precision],
175
  outputs=[output_log]
176
  )
177
 
 
8
 
9
  TEMP_DIR = "temp_processing_dir"
10
 
11
+ def convert_and_upload(token, source_repo, target_repo, precision, target_components):
12
  if not token:
13
  yield "❌ Error: Please provide a valid Hugging Face Write Token."
14
  return
15
  if not target_repo.strip() or "your-username" in target_repo:
16
  yield "❌ Error: Please specify a valid Target Repository (e.g., your-username/repo-name)."
17
  return
18
+ if not target_components:
19
+ yield "❌ Error: Please select at least one component to quantize."
20
+ return
21
 
22
  # Map precision string to PyTorch dtype
23
  if precision == "FP8":
 
59
  local_dir_use_symlinks=False
60
  )
61
 
62
+ # Check if this file belongs to one of the selected target components
63
+ in_target_component = any(f"{comp}/" in file for comp in target_components)
64
+
65
+ # Intercept and quantize only if it's a safetensors file in a selected folder
66
+ if file.endswith(".safetensors") and in_target_component:
67
  yield f"🧠 Quantizing {file} to {precision}..."
68
 
69
  tensors = load_file(local_path)
 
126
  gr.Markdown("# πŸš€ Z-Image Quantizer & Uploader")
127
  gr.Markdown(
128
  "Convert the **Z-Image** or **Z-Image-Turbo** models to lower precisions (FP8, FP16, BF16) and push them directly to your own Hugging Face account.\n\n"
129
+ "**How it works:** This tool sequentially downloads, quantizes the selected files, and uploads everything. "
130
  "It is designed to run safely on free Spaces (16GB RAM) by processing files one at a time."
131
  )
132
 
 
146
  value="Tongyi-MAI/Z-Image-Turbo",
147
  label="Source Repository"
148
  )
149
+
150
+ # Added checkbox group for granular component control
151
+ target_components = gr.CheckboxGroup(
152
+ choices=["text_encoder", "transformer"],
153
+ value=["text_encoder", "transformer"],
154
+ label="Components to Quantize",
155
+ info="Select which parts of the model to convert. Unselected parts will be copied as-is."
156
+ )
157
+
158
  precision = gr.Dropdown(
159
  choices=["FP8", "FP16", "BF16"],
160
  value="FP8",
 
186
 
187
  start_btn.click(
188
  fn=convert_and_upload,
189
+ inputs=[hf_token, source_repo, target_repo, precision, target_components],
190
  outputs=[output_log]
191
  )
192