Python
Fix multiple issues in wan2gp-downloads plugin
Calixto Ong564359e39f8e
diff --git a/plugins/wan2gp-downloads/plugin.py b/plugins/wan2gp-downloads/plugin.pyindex 6a33a26..9c77abd 100644--- a/plugins/wan2gp-downloads/plugin.py+++ b/plugins/wan2gp-downloads/plugin.py@@ -38,7 +38,7 @@ class DownloadsPlugin(WAN2GPPlugin):self.download_loras_btn.click(fn=self.download_loras_action,inputs=[],- outputs=[self.download_status_row, self.download_status]+ outputs=[self.download_status]).then(fn=self.refresh_lora_list,inputs=[self.state, self.lset_name, self.loras_choices],@@ -47,28 +47,27 @@ class DownloadsPlugin(WAN2GPPlugin):def download_loras_action(self):from huggingface_hub import snapshot_download- yield gr.Row(visible=True), "<B><FONT SIZE=3>Please wait while the Loras are being downloaded</B></FONT>"+ 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_dowload")+ tmp_path = os.path.join(lora_dir, "tmp_lora_download")import globsnapshot_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, Path(f).parts[-1])- if os.path.isfile(target_file):- os.remove(f)- else:- shutil.move(f, lora_dir)- try:- os.remove(tmp_path)- except:- pass- yield gr.Row(visible=True), "<B><FONT SIZE=3>Loras have been completely downloaded</B></FONT>"+ 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:+ pass+ yield "<B><FONT SIZE=3>Loras have been completely downloaded</B></FONT>"from datetime import datetime- import timedt = 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 the {dt} at {time.time()} on the {time.time()}")+ writer.write(f"Loras downloaded on {dt} at {tm}")return