Spaces:
Running
on
Zero
Running
on
Zero
Update app_lora.py
Browse files- app_lora.py +55 -0
app_lora.py
CHANGED
|
@@ -55,6 +55,60 @@ default_prompt_i2v = "make this image come alive, cinematic motion, smooth anima
|
|
| 55 |
default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def _calculate_new_dimensions_wan(pil_image, mod_val, calculation_max_area,
|
| 59 |
min_slider_h, max_slider_h,
|
| 60 |
min_slider_w, max_slider_w,
|
|
@@ -132,6 +186,7 @@ def generate_video(input_image, prompt, height, width,
|
|
| 132 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 133 |
video_path = tmpfile.name
|
| 134 |
export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
|
|
|
|
| 135 |
return video_path, current_seed
|
| 136 |
|
| 137 |
with gr.Blocks() as demo:
|
|
|
|
| 55 |
default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
|
| 56 |
|
| 57 |
|
| 58 |
+
HF_MODEL = os.environ.get("HF_UPLOAD_REPO", "rahul7star/VideoExplain")
|
| 59 |
+
from huggingface_hub import HfApi, upload_file
|
| 60 |
+
import os
|
| 61 |
+
import uuid
|
| 62 |
+
import logging
|
| 63 |
+
|
| 64 |
+
import os
|
| 65 |
+
import uuid
|
| 66 |
+
import logging
|
| 67 |
+
from datetime import datetime
|
| 68 |
+
from huggingface_hub import HfApi, upload_file
|
| 69 |
+
|
| 70 |
+
def upload_to_hf(video_path, summary_text):
|
| 71 |
+
api = HfApi()
|
| 72 |
+
|
| 73 |
+
# Create a date-based folder (YYYY-MM-DD)
|
| 74 |
+
today_str = datetime.now().strftime("%Y-%m-%d")
|
| 75 |
+
date_folder = today_str
|
| 76 |
+
|
| 77 |
+
# Generate a unique subfolder for this upload
|
| 78 |
+
unique_subfolder = f"Wan21-I2V-upload_{uuid.uuid4().hex[:8]}"
|
| 79 |
+
hf_folder = f"{date_folder}/{unique_subfolder}"
|
| 80 |
+
logging.info(f"Uploading files to HF folder: {hf_folder} in repo {HF_MODEL}")
|
| 81 |
+
|
| 82 |
+
# Upload video
|
| 83 |
+
video_filename = os.path.basename(video_path)
|
| 84 |
+
video_hf_path = f"{hf_folder}/{video_filename}"
|
| 85 |
+
upload_file(
|
| 86 |
+
path_or_fileobj=video_path,
|
| 87 |
+
path_in_repo=video_hf_path,
|
| 88 |
+
repo_id=HF_MODEL,
|
| 89 |
+
repo_type="model",
|
| 90 |
+
token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
|
| 91 |
+
)
|
| 92 |
+
logging.info(f"✅ Uploaded video to HF: {video_hf_path}")
|
| 93 |
+
|
| 94 |
+
# Upload summary.txt
|
| 95 |
+
summary_file = "/tmp/summary.txt"
|
| 96 |
+
with open(summary_file, "w", encoding="utf-8") as f:
|
| 97 |
+
f.write(summary_text)
|
| 98 |
+
|
| 99 |
+
summary_hf_path = f"{hf_folder}/summary.txt"
|
| 100 |
+
upload_file(
|
| 101 |
+
path_or_fileobj=summary_file,
|
| 102 |
+
path_in_repo=summary_hf_path,
|
| 103 |
+
repo_id=HF_MODEL,
|
| 104 |
+
repo_type="model",
|
| 105 |
+
token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
|
| 106 |
+
)
|
| 107 |
+
logging.info(f"✅ Uploaded summary to HF: {summary_hf_path}")
|
| 108 |
+
|
| 109 |
+
return hf_folder
|
| 110 |
+
|
| 111 |
+
|
| 112 |
def _calculate_new_dimensions_wan(pil_image, mod_val, calculation_max_area,
|
| 113 |
min_slider_h, max_slider_h,
|
| 114 |
min_slider_w, max_slider_w,
|
|
|
|
| 186 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 187 |
video_path = tmpfile.name
|
| 188 |
export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
|
| 189 |
+
hf_folder = upload_to_hf(video_path, prompt)
|
| 190 |
return video_path, current_seed
|
| 191 |
|
| 192 |
with gr.Blocks() as demo:
|