rahul7star commited on
Commit
39dbd73
·
verified ·
1 Parent(s): e592b42

Update wan2_fast.py

Browse files
Files changed (1) hide show
  1. wan2_fast.py +52 -0
wan2_fast.py CHANGED
@@ -36,7 +36,58 @@ MODEL_ID = "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers"
36
 
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
40
 
41
 
42
 
@@ -281,6 +332,7 @@ def generate_video(prompt, height, width,
281
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
282
  video_path = tmpfile.name
283
  export_to_video(output_frames_list, video_path, fps=FIXED_OUTPUT_FPS)
 
284
  return video_path, current_seed
285
 
286
 
 
36
 
37
 
38
 
39
+ HF_MODEL = os.environ.get("HF_UPLOAD_REPO", "rahul7star/VideoExplain")
40
+ from huggingface_hub import HfApi, upload_file
41
+ import os
42
+ import uuid
43
+ import logging
44
+
45
+ import os
46
+ import uuid
47
+ import logging
48
+ from datetime import datetime
49
+ from huggingface_hub import HfApi, upload_file
50
+
51
+ def upload_to_hf(video_path, summary_text):
52
+ api = HfApi()
53
+
54
+ # Create a date-based folder (YYYY-MM-DD)
55
+ today_str = datetime.now().strftime("%Y-%m-%d")
56
+ date_folder = today_str
57
+
58
+ # Generate a unique subfolder for this upload
59
+ unique_subfolder = f"Wan21-I2V-upload_{uuid.uuid4().hex[:8]}"
60
+ hf_folder = f"{date_folder}/{unique_subfolder}"
61
+ logging.info(f"Uploading files to HF folder: {hf_folder} in repo {HF_MODEL}")
62
+
63
+ # Upload video
64
+ video_filename = os.path.basename(video_path)
65
+ video_hf_path = f"{hf_folder}/{video_filename}"
66
+ upload_file(
67
+ path_or_fileobj=video_path,
68
+ path_in_repo=video_hf_path,
69
+ repo_id=HF_MODEL,
70
+ repo_type="model",
71
+ token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
72
+ )
73
+ logging.info(f"✅ Uploaded video to HF: {video_hf_path}")
74
+
75
+ # Upload summary.txt
76
+ summary_file = "/tmp/summary.txt"
77
+ with open(summary_file, "w", encoding="utf-8") as f:
78
+ f.write(summary_text)
79
+
80
+ summary_hf_path = f"{hf_folder}/summary.txt"
81
+ upload_file(
82
+ path_or_fileobj=summary_file,
83
+ path_in_repo=summary_hf_path,
84
+ repo_id=HF_MODEL,
85
+ repo_type="model",
86
+ token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
87
+ )
88
+ logging.info(f"✅ Uploaded summary to HF: {summary_hf_path}")
89
 
90
+ return hf_folder
91
 
92
 
93
 
 
332
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
333
  video_path = tmpfile.name
334
  export_to_video(output_frames_list, video_path, fps=FIXED_OUTPUT_FPS)
335
+ hf_folder = upload_to_hf(video_path, prompt)
336
  return video_path, current_seed
337
 
338