Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,9 +14,6 @@ from videosys.models.cogvideo.pipeline import CogVideoPABConfig
|
|
| 14 |
import psutil
|
| 15 |
import GPUtil
|
| 16 |
|
| 17 |
-
# import threading
|
| 18 |
-
# task_running = threading.Event()
|
| 19 |
-
|
| 20 |
|
| 21 |
|
| 22 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -245,23 +242,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 245 |
disk_status = gr.Textbox(label="Disk", scale=1)
|
| 246 |
gpu_status = gr.Textbox(label="GPU Memory", scale=1)
|
| 247 |
refresh_button = gr.Button("Refresh", scale=1, size="sm")
|
| 248 |
-
with gr.Column(elem_classes="server-status"):
|
| 249 |
-
gr.Markdown("#### Server Status")
|
| 250 |
-
|
| 251 |
-
with gr.Row():
|
| 252 |
-
with gr.Column(scale=1):
|
| 253 |
-
cpu_status = gr.Textbox(label="CPU")
|
| 254 |
-
with gr.Column(scale=1):
|
| 255 |
-
memory_status = gr.Textbox(label="Memory")
|
| 256 |
-
|
| 257 |
-
with gr.Row():
|
| 258 |
-
with gr.Column(scale=1):
|
| 259 |
-
disk_status = gr.Textbox(label="Disk")
|
| 260 |
-
with gr.Column(scale=1):
|
| 261 |
-
gpu_status = gr.Textbox(label="GPU Memory")
|
| 262 |
-
|
| 263 |
-
with gr.Row():
|
| 264 |
-
refresh_button = gr.Button("Refresh", size="sm")
|
| 265 |
|
| 266 |
with gr.Column():
|
| 267 |
with gr.Row():
|
|
@@ -278,18 +258,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 278 |
task_status = gr.Textbox(label="任务状态", visible=False)
|
| 279 |
|
| 280 |
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
# def run_task(func, *args):
|
| 284 |
-
# if task_running.is_set():
|
| 285 |
-
# return None, gr.update(value="Please wait for another running end", visible=True), gr.update(visible=False)
|
| 286 |
-
|
| 287 |
-
# task_running.set()
|
| 288 |
-
# try:
|
| 289 |
-
# result = func(*args)
|
| 290 |
-
# return result, gr.update(visible=False), gr.update(visible=True)
|
| 291 |
-
# finally:
|
| 292 |
-
# task_running.clear()
|
| 293 |
|
| 294 |
def generate_vanilla(prompt, num_inference_steps, guidance_scale, progress=gr.Progress(track_tqdm=True)):
|
| 295 |
engine = load_model()
|
|
@@ -298,7 +267,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 298 |
elapsed_time = time() - t
|
| 299 |
video_update = gr.update(visible=True, value=video_path)
|
| 300 |
elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
|
| 301 |
-
|
| 302 |
return video_path, video_update, elapsed_time
|
| 303 |
|
| 304 |
def generate_vs(prompt, num_inference_steps, guidance_scale, threshold, gap, progress=gr.Progress(track_tqdm=True)):
|
|
@@ -310,7 +279,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 310 |
elapsed_time = time() - t
|
| 311 |
video_update = gr.update(visible=True, value=video_path)
|
| 312 |
elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
|
| 313 |
-
|
| 314 |
return video_path, video_update, elapsed_time
|
| 315 |
|
| 316 |
def enhance_prompt_func(prompt):
|
|
@@ -323,7 +292,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 323 |
try:
|
| 324 |
gpus = GPUtil.getGPUs()
|
| 325 |
if gpus:
|
| 326 |
-
gpu = gpus[0]
|
| 327 |
gpu_memory = f"{gpu.memoryUsed}/{gpu.memoryTotal}MB ({gpu.memoryUtil*100:.1f}%)"
|
| 328 |
else:
|
| 329 |
gpu_memory = "No GPU found"
|
|
@@ -347,20 +316,19 @@ with gr.Blocks(css=css) as demo:
|
|
| 347 |
status['gpu_memory']
|
| 348 |
)
|
| 349 |
|
| 350 |
-
|
| 351 |
generate_button.click(
|
| 352 |
generate_vanilla,
|
| 353 |
inputs=[prompt, num_inference_steps, guidance_scale],
|
| 354 |
outputs=[video_output, download_video_button, elapsed_time],
|
| 355 |
)
|
| 356 |
-
|
| 357 |
generate_button_vs.click(
|
| 358 |
generate_vs,
|
| 359 |
inputs=[prompt, num_inference_steps, guidance_scale, pab_threshold, pab_gap],
|
| 360 |
outputs=[video_output_vs, download_video_button_vs, elapsed_time_vs],
|
| 361 |
)
|
| 362 |
|
| 363 |
-
|
| 364 |
enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
|
| 365 |
|
| 366 |
|
|
@@ -369,4 +337,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 369 |
|
| 370 |
if __name__ == "__main__":
|
| 371 |
demo.queue(max_size=10, default_concurrency_limit=1)
|
| 372 |
-
demo.launch()
|
|
|
|
| 14 |
import psutil
|
| 15 |
import GPUtil
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 242 |
disk_status = gr.Textbox(label="Disk", scale=1)
|
| 243 |
gpu_status = gr.Textbox(label="GPU Memory", scale=1)
|
| 244 |
refresh_button = gr.Button("Refresh", scale=1, size="sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
with gr.Column():
|
| 247 |
with gr.Row():
|
|
|
|
| 258 |
task_status = gr.Textbox(label="任务状态", visible=False)
|
| 259 |
|
| 260 |
|
| 261 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
def generate_vanilla(prompt, num_inference_steps, guidance_scale, progress=gr.Progress(track_tqdm=True)):
|
| 264 |
engine = load_model()
|
|
|
|
| 267 |
elapsed_time = time() - t
|
| 268 |
video_update = gr.update(visible=True, value=video_path)
|
| 269 |
elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
|
| 270 |
+
|
| 271 |
return video_path, video_update, elapsed_time
|
| 272 |
|
| 273 |
def generate_vs(prompt, num_inference_steps, guidance_scale, threshold, gap, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 279 |
elapsed_time = time() - t
|
| 280 |
video_update = gr.update(visible=True, value=video_path)
|
| 281 |
elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
|
| 282 |
+
|
| 283 |
return video_path, video_update, elapsed_time
|
| 284 |
|
| 285 |
def enhance_prompt_func(prompt):
|
|
|
|
| 292 |
try:
|
| 293 |
gpus = GPUtil.getGPUs()
|
| 294 |
if gpus:
|
| 295 |
+
gpu = gpus[0] # 只获取第一个GPU的信息
|
| 296 |
gpu_memory = f"{gpu.memoryUsed}/{gpu.memoryTotal}MB ({gpu.memoryUtil*100:.1f}%)"
|
| 297 |
else:
|
| 298 |
gpu_memory = "No GPU found"
|
|
|
|
| 316 |
status['gpu_memory']
|
| 317 |
)
|
| 318 |
|
| 319 |
+
|
| 320 |
generate_button.click(
|
| 321 |
generate_vanilla,
|
| 322 |
inputs=[prompt, num_inference_steps, guidance_scale],
|
| 323 |
outputs=[video_output, download_video_button, elapsed_time],
|
| 324 |
)
|
| 325 |
+
|
| 326 |
generate_button_vs.click(
|
| 327 |
generate_vs,
|
| 328 |
inputs=[prompt, num_inference_steps, guidance_scale, pab_threshold, pab_gap],
|
| 329 |
outputs=[video_output_vs, download_video_button_vs, elapsed_time_vs],
|
| 330 |
)
|
| 331 |
|
|
|
|
| 332 |
enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
|
| 333 |
|
| 334 |
|
|
|
|
| 337 |
|
| 338 |
if __name__ == "__main__":
|
| 339 |
demo.queue(max_size=10, default_concurrency_limit=1)
|
| 340 |
+
demo.launch()
|