Skip to content
Python

Address Copilot review feedback: fix glob logic, log accuracy, cleanup UI, and reorganize imports

Calixto Ongae37540f5f69
diff --git a/plugins/wan2gp-downloads/plugin.py b/plugins/wan2gp-downloads/plugin.py
index 7c1ae50..a78f369 100644
--- a/plugins/wan2gp-downloads/plugin.py
+++ b/plugins/wan2gp-downloads/plugin.py
@@ -2,7 +2,10 @@ import gradio as gr
from shared.utils.plugins import WAN2GPPlugin
import os
import shutil
+import glob
from pathlib import Path
+from datetime import datetime
+from huggingface_hub import snapshot_download
class DownloadsPlugin(WAN2GPPlugin):
def __init__(self):
@@ -33,8 +36,7 @@ class DownloadsPlugin(WAN2GPPlugin):
self.download_loras_btn = gr.Button("---> Let the Lora's Festival Start !", scale=1)
with gr.Row(scale=1):
gr.Markdown("")
- with gr.Row() as self.download_status_row:
- self.download_status = gr.Markdown()
+ self.download_status = gr.Markdown()
self.download_loras_btn.click(
fn=self.download_loras_action,
inputs=[],
@@ -46,27 +48,28 @@ class DownloadsPlugin(WAN2GPPlugin):
)
def download_loras_action(self):
- from huggingface_hub import snapshot_download
yield "<B><FONT SIZE=3>Please wait while the Loras are being downloaded</B></FONT>"
lora_dir = self.get_lora_dir("i2v")
log_path = os.path.join(lora_dir, "log.txt")
if not os.path.isfile(log_path):
tmp_path = os.path.join(lora_dir, "tmp_lora_download")
- import glob
snapshot_download(repo_id="DeepBeepMeep/Wan2.1", allow_patterns="loras_i2v/*", local_dir=tmp_path)
for f in glob.glob(os.path.join(tmp_path, "loras_i2v", "*")):
- target_file = os.path.join(lora_dir, os.path.basename(f))
- if os.path.exists(target_file):
- os.remove(target_file)
- shutil.move(f, lora_dir)
+ if os.path.isfile(f):
+ target_file = os.path.join(lora_dir, os.path.basename(f))
+ if os.path.exists(target_file):
+ os.remove(target_file)
+ shutil.move(f, lora_dir)
try:
shutil.rmtree(tmp_path)
except Exception as e:
print(f"Failed to remove tmp_path: {e}")
- from datetime import datetime
- dt = datetime.today().strftime('%Y-%m-%d')
- tm = datetime.now().strftime('%H:%M:%S')
- with open(log_path, "w", encoding="utf-8") as writer:
- writer.write(f"Loras downloaded on {dt} at {tm}")
+ dt = datetime.today().strftime('%Y-%m-%d')
+ tm = datetime.now().strftime('%H:%M:%S')
+ with open(log_path, "w", encoding="utf-8") as writer:
+ writer.write(f"Loras downloaded on {dt} at {tm}")
+ yield "<B><FONT SIZE=3 COLOR=green>Loras's Festival is successfully STARTED !</B></FONT>"
+ else:
+ yield "<B><FONT SIZE=3>Loras's Festival is already ON ! (Loras already downloaded)</B></FONT>"
return