ArrcttacsrjksX commited on
Commit
205eccb
·
verified ·
1 Parent(s): 6f74e10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -37,7 +37,7 @@ if not os.path.exists(model_path):
37
  def run_command_and_save(
38
  prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
39
  batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
40
- control_net_cpu, canny, verbose, init_image=None
41
  ):
42
  try:
43
  # Lưu ảnh đầu vào nếu được cung cấp
@@ -45,7 +45,6 @@ def run_command_and_save(
45
  if init_image is not None:
46
  init_image_path = "input_image.png"
47
  init_image.save(init_image_path)
48
-
49
  # Tạo lệnh chạy
50
  command = [
51
  f"./{app_path}",
@@ -63,8 +62,11 @@ def run_command_and_save(
63
  "--schedule", schedule,
64
  "--clip-skip", str(clip_skip),
65
  ]
66
-
67
- # Thêm tùy chọn VAE tiling
 
 
 
68
  if vae_tiling:
69
  command.append("--vae-tiling")
70
  if vae_on_cpu:
@@ -79,11 +81,9 @@ def run_command_and_save(
79
  command.append("--canny")
80
  if verbose:
81
  command.append("-v")
82
-
83
  # Thêm ảnh đầu vào nếu có
84
  if mode == "img2img" and init_image_path:
85
  command.extend(["-i", init_image_path])
86
-
87
  # Chạy lệnh và hiển thị log theo thời gian thực
88
  process = subprocess.Popen(
89
  command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
@@ -92,7 +92,6 @@ def run_command_and_save(
92
  for line in process.stdout:
93
  logs.append(line.strip()) # Lưu log vào danh sách
94
  print(line, end="") # In log ra màn hình
95
-
96
  process.wait() # Đợi tiến trình hoàn thành
97
  # Kiểm tra kết quả và trả về
98
  if process.returncode == 0:
@@ -106,10 +105,8 @@ def run_command_and_save(
106
  local_folder = os.path.join(".", folder_name)
107
  os.makedirs(local_folder, exist_ok=True)
108
  local_file_path = os.path.join(local_folder, file_name)
109
-
110
  # Di chuyển file đến thư mục mới
111
  os.rename(output_path, local_file_path)
112
-
113
  # Upload file lên Hugging Face Hub
114
  api = HfApi()
115
  repo_id = "ArrcttacsrjksX/Deffusion"
@@ -144,7 +141,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
144
  Generate stunning images from text or modify existing images with AI-powered tools.
145
  """
146
  )
147
-
148
  # Thiết lập giao diện
149
  with gr.Row():
150
  with gr.Column():
@@ -158,7 +154,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
158
  label="Drop Image (for img2img mode)", type="pil", visible=False
159
  )
160
  mode.change(toggle_image_input, inputs=mode, outputs=init_image)
161
-
162
  with gr.Column():
163
  height = gr.Slider(
164
  128, 1024, value=512, step=64, label="Image Height (px)", interactive=True
@@ -178,7 +173,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
178
  strength = gr.Slider(
179
  0, 1, value=0.75, step=0.01, label="Strength (img2img only)", interactive=True
180
  )
181
-
182
  with gr.Row():
183
  sampling_method = gr.Dropdown(
184
  choices=["euler", "euler_a", "heun", "dpm2", "dpm++2s_a", "dpm++2m", "dpm++2mv2", "ipndm", "ipndm_v", "lcm"],
@@ -191,7 +185,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
191
  choices=["discrete", "karras", "exponential", "ays", "gits"],
192
  value="discrete", label="Denoiser Sigma Schedule", interactive=True
193
  )
194
-
195
  with gr.Row():
196
  clip_skip = gr.Slider(
197
  -1, 10, value=-1, step=1, label="CLIP Skip Layers", interactive=True
@@ -203,22 +196,26 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
203
  control_net_cpu = gr.Checkbox(label="ControlNet on CPU", value=False)
204
  canny = gr.Checkbox(label="Canny Preprocessor", value=False)
205
  verbose = gr.Checkbox(label="Verbose Logging", value=False)
206
-
 
 
 
 
 
 
207
  # Nút chạy và kết quả
208
  with gr.Row():
209
  run_button = gr.Button("🚀 Run", variant="primary")
210
-
211
  with gr.Row():
212
  output_image = gr.File(label="Download Image", interactive=False)
213
  log_output = gr.Textbox(label="Logs", interactive=False, lines=10)
214
-
215
  # Kết nối nút Run với hàm xử lý
216
  run_button.click(
217
  run_command_and_save,
218
  inputs=[
219
  prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
220
  batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
221
- control_net_cpu, canny, verbose, init_image
222
  ],
223
  outputs=[output_image, log_output],
224
  )
 
37
  def run_command_and_save(
38
  prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
39
  batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
40
+ control_net_cpu, canny, verbose, init_image=None, weight_type=None
41
  ):
42
  try:
43
  # Lưu ảnh đầu vào nếu được cung cấp
 
45
  if init_image is not None:
46
  init_image_path = "input_image.png"
47
  init_image.save(init_image_path)
 
48
  # Tạo lệnh chạy
49
  command = [
50
  f"./{app_path}",
 
62
  "--schedule", schedule,
63
  "--clip-skip", str(clip_skip),
64
  ]
65
+ # Thêm tùy chọn Weight Type nếu được chỉ định
66
+ if weight_type:
67
+ command.extend(["--type", weight_type])
68
+
69
+ # Thêm các tùy chọn khác
70
  if vae_tiling:
71
  command.append("--vae-tiling")
72
  if vae_on_cpu:
 
81
  command.append("--canny")
82
  if verbose:
83
  command.append("-v")
 
84
  # Thêm ảnh đầu vào nếu có
85
  if mode == "img2img" and init_image_path:
86
  command.extend(["-i", init_image_path])
 
87
  # Chạy lệnh và hiển thị log theo thời gian thực
88
  process = subprocess.Popen(
89
  command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
 
92
  for line in process.stdout:
93
  logs.append(line.strip()) # Lưu log vào danh sách
94
  print(line, end="") # In log ra màn hình
 
95
  process.wait() # Đợi tiến trình hoàn thành
96
  # Kiểm tra kết quả và trả về
97
  if process.returncode == 0:
 
105
  local_folder = os.path.join(".", folder_name)
106
  os.makedirs(local_folder, exist_ok=True)
107
  local_file_path = os.path.join(local_folder, file_name)
 
108
  # Di chuyển file đến thư mục mới
109
  os.rename(output_path, local_file_path)
 
110
  # Upload file lên Hugging Face Hub
111
  api = HfApi()
112
  repo_id = "ArrcttacsrjksX/Deffusion"
 
141
  Generate stunning images from text or modify existing images with AI-powered tools.
142
  """
143
  )
 
144
  # Thiết lập giao diện
145
  with gr.Row():
146
  with gr.Column():
 
154
  label="Drop Image (for img2img mode)", type="pil", visible=False
155
  )
156
  mode.change(toggle_image_input, inputs=mode, outputs=init_image)
 
157
  with gr.Column():
158
  height = gr.Slider(
159
  128, 1024, value=512, step=64, label="Image Height (px)", interactive=True
 
173
  strength = gr.Slider(
174
  0, 1, value=0.75, step=0.01, label="Strength (img2img only)", interactive=True
175
  )
 
176
  with gr.Row():
177
  sampling_method = gr.Dropdown(
178
  choices=["euler", "euler_a", "heun", "dpm2", "dpm++2s_a", "dpm++2m", "dpm++2mv2", "ipndm", "ipndm_v", "lcm"],
 
185
  choices=["discrete", "karras", "exponential", "ays", "gits"],
186
  value="discrete", label="Denoiser Sigma Schedule", interactive=True
187
  )
 
188
  with gr.Row():
189
  clip_skip = gr.Slider(
190
  -1, 10, value=-1, step=1, label="CLIP Skip Layers", interactive=True
 
196
  control_net_cpu = gr.Checkbox(label="ControlNet on CPU", value=False)
197
  canny = gr.Checkbox(label="Canny Preprocessor", value=False)
198
  verbose = gr.Checkbox(label="Verbose Logging", value=False)
199
+ with gr.Row():
200
+ weight_type = gr.Dropdown(
201
+ choices=["f32", "f16", "q4_0", "q4_1", "q5_0", "q5_1", "q8_0", "q2_K", "q3_K", "q4_K"],
202
+ value=None, # Mặc định không chọn
203
+ label="Weight Type (Optional)",
204
+ interactive=True
205
+ )
206
  # Nút chạy và kết quả
207
  with gr.Row():
208
  run_button = gr.Button("🚀 Run", variant="primary")
 
209
  with gr.Row():
210
  output_image = gr.File(label="Download Image", interactive=False)
211
  log_output = gr.Textbox(label="Logs", interactive=False, lines=10)
 
212
  # Kết nối nút Run với hàm xử lý
213
  run_button.click(
214
  run_command_and_save,
215
  inputs=[
216
  prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
217
  batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
218
+ control_net_cpu, canny, verbose, init_image, weight_type # Thêm weight_type
219
  ],
220
  outputs=[output_image, log_output],
221
  )