Update app.py
Browse files
app.py
CHANGED
|
@@ -415,4 +415,43 @@ if __name__ == "__main__":
|
|
| 415 |
server_port=7860,
|
| 416 |
share=True,
|
| 417 |
favicon_path="favicon.ico" if os.path.exists("favicon.ico") else None
|
| 418 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
server_port=7860,
|
| 416 |
share=True,
|
| 417 |
favicon_path="favicon.ico" if os.path.exists("favicon.ico") else None
|
| 418 |
+
)
|
| 419 |
+
# 在 create_gradio_interface() 函数中添加内存管理按钮
|
| 420 |
+
def create_gradio_interface():
|
| 421 |
+
with gr.Blocks(title="AI时尚设计师", theme="soft") as demo:
|
| 422 |
+
# ... [现有代码] ...
|
| 423 |
+
|
| 424 |
+
# 添加内存管理部分
|
| 425 |
+
with gr.Row():
|
| 426 |
+
gr.Markdown("### 内存管理")
|
| 427 |
+
unload_caption_btn = gr.Button("卸载描述模型")
|
| 428 |
+
unload_sd_btn = gr.Button("卸载设计模型")
|
| 429 |
+
unload_controlnet_btn = gr.Button("卸载3D模型")
|
| 430 |
+
full_cleanup_btn = gr.Button("清理所有模型", variant="stop")
|
| 431 |
+
|
| 432 |
+
# 内存管理事件
|
| 433 |
+
unload_caption_btn.click(
|
| 434 |
+
fn=lambda: model_manager.unload_model("caption"),
|
| 435 |
+
inputs=[],
|
| 436 |
+
outputs=[]
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
unload_sd_btn.click(
|
| 440 |
+
fn=lambda: model_manager.unload_model("sd"),
|
| 441 |
+
inputs=[],
|
| 442 |
+
outputs=[]
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
unload_controlnet_btn.click(
|
| 446 |
+
fn=lambda: model_manager.unload_model("controlnet"),
|
| 447 |
+
inputs=[],
|
| 448 |
+
outputs=[]
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
full_cleanup_btn.click(
|
| 452 |
+
fn=model_manager.cleanup,
|
| 453 |
+
inputs=[],
|
| 454 |
+
outputs=[]
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
return demo
|