ArrcttacsrjksX commited on
Commit
13869fb
·
verified ·
1 Parent(s): 865d1fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -9
app.py CHANGED
@@ -28,12 +28,15 @@ def download_file(url, output_path, token):
28
  if not os.path.exists(app_path):
29
  download_file(app_url, app_path, hf_token)
30
  subprocess.run(["chmod", "+x", app_path]) # Thay đổi quyền thực thi
31
-
32
  if not os.path.exists(model_path):
33
  download_file(model_url, model_path, hf_token)
34
 
35
  # Hàm xử lý chạy ứng dụng
36
- def run_command(prompt, mode, height, width, steps, seed, init_image=None):
 
 
 
 
37
  try:
38
  # Lưu ảnh đầu vào nếu được cung cấp
39
  init_image_path = None
@@ -51,8 +54,30 @@ def run_command(prompt, mode, height, width, steps, seed, init_image=None):
51
  "-W", str(width),
52
  "--steps", str(steps),
53
  "-s", str(seed),
 
 
 
 
 
 
54
  ]
55
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  # Thêm ảnh đầu vào nếu có
57
  if mode == "img2img" and init_image_path:
58
  command.extend(["-i", init_image_path])
@@ -65,9 +90,8 @@ def run_command(prompt, mode, height, width, steps, seed, init_image=None):
65
  for line in process.stdout:
66
  logs.append(line.strip()) # Lưu log vào danh sách
67
  print(line, end="") # In log ra màn hình
68
-
69
- process.wait() # Đợi tiến trình hoàn thành
70
 
 
71
  # Kiểm tra kết quả và trả về
72
  if process.returncode == 0:
73
  output_path = "./output.png" # Đường dẫn ảnh đầu ra mặc định
@@ -91,7 +115,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
91
  Generate stunning images from text or modify existing images with AI-powered tools.
92
  """
93
  )
94
-
95
  # Thiết lập giao diện
96
  with gr.Row():
97
  with gr.Column():
@@ -119,11 +143,42 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
119
  seed = gr.Slider(
120
  -1, 10000, value=42, step=1, label="Random Seed (-1 for random)", interactive=True
121
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  # Nút chạy và kết quả
124
  with gr.Row():
125
  run_button = gr.Button("🚀 Run", variant="primary")
126
-
127
  with gr.Row():
128
  output_image = gr.File(label="Download Image", interactive=False)
129
  log_output = gr.Textbox(label="Logs", interactive=False, lines=10)
@@ -131,8 +186,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
131
  # Kết nối nút Run với hàm xử lý
132
  run_button.click(
133
  run_command,
134
- inputs=[prompt, mode, height, width, steps, seed, init_image],
 
 
 
 
135
  outputs=[output_image, log_output],
136
  )
137
 
138
- demo.launch()
 
28
  if not os.path.exists(app_path):
29
  download_file(app_url, app_path, hf_token)
30
  subprocess.run(["chmod", "+x", app_path]) # Thay đổi quyền thực thi
 
31
  if not os.path.exists(model_path):
32
  download_file(model_url, model_path, hf_token)
33
 
34
  # Hàm xử lý chạy ứng dụng
35
+ def run_command(
36
+ prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
37
+ batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
38
+ control_net_cpu, canny, verbose, init_image=None
39
+ ):
40
  try:
41
  # Lưu ảnh đầu vào nếu được cung cấp
42
  init_image_path = None
 
54
  "-W", str(width),
55
  "--steps", str(steps),
56
  "-s", str(seed),
57
+ "--cfg-scale", str(cfg_scale),
58
+ "--strength", str(strength),
59
+ "--sampling-method", sampling_method,
60
+ "--batch-count", str(batch_count),
61
+ "--schedule", schedule,
62
+ "--clip-skip", str(clip_skip),
63
  ]
64
+
65
+ # Thêm tùy chọn VAE tiling
66
+ if vae_tiling:
67
+ command.append("--vae-tiling")
68
+ if vae_on_cpu:
69
+ command.append("--vae-on-cpu")
70
+ if clip_on_cpu:
71
+ command.append("--clip-on-cpu")
72
+ if diffusion_fa:
73
+ command.append("--diffusion-fa")
74
+ if control_net_cpu:
75
+ command.append("--control-net-cpu")
76
+ if canny:
77
+ command.append("--canny")
78
+ if verbose:
79
+ command.append("-v")
80
+
81
  # Thêm ảnh đầu vào nếu có
82
  if mode == "img2img" and init_image_path:
83
  command.extend(["-i", init_image_path])
 
90
  for line in process.stdout:
91
  logs.append(line.strip()) # Lưu log vào danh sách
92
  print(line, end="") # In log ra màn hình
 
 
93
 
94
+ process.wait() # Đợi tiến trình hoàn thành
95
  # Kiểm tra kết quả và trả về
96
  if process.returncode == 0:
97
  output_path = "./output.png" # Đường dẫn ảnh đầu ra mặc định
 
115
  Generate stunning images from text or modify existing images with AI-powered tools.
116
  """
117
  )
118
+
119
  # Thiết lập giao diện
120
  with gr.Row():
121
  with gr.Column():
 
143
  seed = gr.Slider(
144
  -1, 10000, value=42, step=1, label="Random Seed (-1 for random)", interactive=True
145
  )
146
+ cfg_scale = gr.Slider(
147
+ 1, 20, value=7, step=0.1, label="CFG Scale", interactive=True
148
+ )
149
+ strength = gr.Slider(
150
+ 0, 1, value=0.75, step=0.01, label="Strength (img2img only)", interactive=True
151
+ )
152
+
153
+ with gr.Row():
154
+ sampling_method = gr.Dropdown(
155
+ choices=["euler", "euler_a", "heun", "dpm2", "dpm++2s_a", "dpm++2m", "dpm++2mv2", "ipndm", "ipndm_v", "lcm"],
156
+ value="euler_a", label="Sampling Method", interactive=True
157
+ )
158
+ batch_count = gr.Slider(
159
+ 1, 10, value=1, step=1, label="Batch Count", interactive=True
160
+ )
161
+ schedule = gr.Dropdown(
162
+ choices=["discrete", "karras", "exponential", "ays", "gits"],
163
+ value="discrete", label="Denoiser Sigma Schedule", interactive=True
164
+ )
165
+
166
+ with gr.Row():
167
+ clip_skip = gr.Slider(
168
+ -1, 10, value=-1, step=1, label="CLIP Skip Layers", interactive=True
169
+ )
170
+ vae_tiling = gr.Checkbox(label="VAE Tiling", value=False)
171
+ vae_on_cpu = gr.Checkbox(label="VAE on CPU", value=False)
172
+ clip_on_cpu = gr.Checkbox(label="CLIP on CPU", value=False)
173
+ diffusion_fa = gr.Checkbox(label="Diffusion Flash Attention", value=False)
174
+ control_net_cpu = gr.Checkbox(label="ControlNet on CPU", value=False)
175
+ canny = gr.Checkbox(label="Canny Preprocessor", value=False)
176
+ verbose = gr.Checkbox(label="Verbose Logging", value=False)
177
 
178
  # Nút chạy và kết quả
179
  with gr.Row():
180
  run_button = gr.Button("🚀 Run", variant="primary")
181
+
182
  with gr.Row():
183
  output_image = gr.File(label="Download Image", interactive=False)
184
  log_output = gr.Textbox(label="Logs", interactive=False, lines=10)
 
186
  # Kết nối nút Run với hàm xử lý
187
  run_button.click(
188
  run_command,
189
+ inputs=[
190
+ prompt, mode, height, width, steps, seed, cfg_scale, strength, sampling_method,
191
+ batch_count, schedule, clip_skip, vae_tiling, vae_on_cpu, clip_on_cpu, diffusion_fa,
192
+ control_net_cpu, canny, verbose, init_image
193
+ ],
194
  outputs=[output_image, log_output],
195
  )
196
 
197
+ demo.launch()