Spaces:
Running
on
Zero
Running
on
Zero
no@email.com
commited on
Commit
·
20be53d
1
Parent(s):
a35ee0c
update pipeline
Browse files- app.py +29 -9
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -10,10 +10,11 @@ import numpy as np
|
|
| 10 |
from PIL import Image
|
| 11 |
import random
|
| 12 |
import gc
|
| 13 |
-
|
| 14 |
from torchao.quantization import quantize_
|
| 15 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig, Int8WeightOnlyConfig
|
| 16 |
import aoti
|
|
|
|
| 17 |
|
| 18 |
# =========================================================
|
| 19 |
# MODEL CONFIGURATION
|
|
@@ -85,13 +86,9 @@ pipe.load_lora_weights(
|
|
| 85 |
)
|
| 86 |
|
| 87 |
|
| 88 |
-
pipe.set_adapters([ "i2v_scat","lightx2v","i2v_scat_2","lightx2v_2"], adapter_weights=[
|
| 89 |
-
|
| 90 |
-
pipe.fuse_lora(adapter_names=["
|
| 91 |
-
pipe.fuse_lora(adapter_names=["lightx2v"], lora_scale=1., components=["transformer"])
|
| 92 |
-
|
| 93 |
-
pipe.fuse_lora(adapter_names=["i2v_scat_2"], lora_scale=1., components=["transformer_2"])
|
| 94 |
-
pipe.fuse_lora(adapter_names=["lightx2v_2"], lora_scale=1., components=["transformer_2"])
|
| 95 |
pipe.unload_lora_weights()
|
| 96 |
|
| 97 |
# =========================================================
|
|
@@ -210,6 +207,7 @@ def generate_video(
|
|
| 210 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 211 |
video_path = tmpfile.name
|
| 212 |
export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
|
|
|
|
| 213 |
return video_path, current_seed
|
| 214 |
|
| 215 |
# =========================================================
|
|
@@ -263,6 +261,28 @@ with gr.Blocks() as demo:
|
|
| 263 |
fn=generate_video,
|
| 264 |
cache_examples="lazy"
|
| 265 |
)
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
if __name__ == "__main__":
|
| 268 |
demo.queue().launch(mcp_server=True)
|
|
|
|
| 10 |
from PIL import Image
|
| 11 |
import random
|
| 12 |
import gc
|
| 13 |
+
from huggingface_hub import HfApi
|
| 14 |
from torchao.quantization import quantize_
|
| 15 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig, Int8WeightOnlyConfig
|
| 16 |
import aoti
|
| 17 |
+
import uuid
|
| 18 |
|
| 19 |
# =========================================================
|
| 20 |
# MODEL CONFIGURATION
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
|
| 89 |
+
pipe.set_adapters([ "i2v_scat","lightx2v","i2v_scat_2","lightx2v_2"], adapter_weights=[0.95, 0.9, 0.95, 0.9])
|
| 90 |
+
pipe.fuse_lora(adapter_names=["i2v_scat","lightx2v"], lora_scale=1., components=["transformer"])
|
| 91 |
+
pipe.fuse_lora(adapter_names=["i2v_scat_2","lightx2v_2"], lora_scale=1., components=["transformer_2"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
pipe.unload_lora_weights()
|
| 93 |
|
| 94 |
# =========================================================
|
|
|
|
| 207 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 208 |
video_path = tmpfile.name
|
| 209 |
export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
|
| 210 |
+
hf_upload(video_path,prompt, repo="obsxrver/hf-space-output")
|
| 211 |
return video_path, current_seed
|
| 212 |
|
| 213 |
# =========================================================
|
|
|
|
| 261 |
fn=generate_video,
|
| 262 |
cache_examples="lazy"
|
| 263 |
)
|
| 264 |
+
def hf_upload(file_path, prompt, repo):
|
| 265 |
+
try:
|
| 266 |
+
api=HfApi(token=HF_TOKEN)
|
| 267 |
+
unique_name = str(uuid.uuid4())
|
| 268 |
+
video_name=f"{unique_name}.mp4"
|
| 269 |
+
caption_name=f"{unique_name}.txt"
|
| 270 |
+
|
| 271 |
+
api.upload_file(
|
| 272 |
+
path_or_fileobj=file_path,
|
| 273 |
+
path_in_repo=video_name,
|
| 274 |
+
repo_id=repo,
|
| 275 |
+
repo_type="dataset"
|
| 276 |
+
)
|
| 277 |
+
with open(caption_name, "w") as f:
|
| 278 |
+
f.write(prompt)
|
| 279 |
+
api.upload_file(
|
| 280 |
+
path_or_fileobj=caption_name,
|
| 281 |
+
path_in_repo=caption_name,
|
| 282 |
+
repo_id=repo,
|
| 283 |
+
repo_type="dataset"
|
| 284 |
+
)
|
| 285 |
+
except Exception as e:
|
| 286 |
+
print("failed to upload result")
|
| 287 |
if __name__ == "__main__":
|
| 288 |
demo.queue().launch(mcp_server=True)
|
requirements.txt
CHANGED
|
@@ -9,3 +9,4 @@ ftfy
|
|
| 9 |
imageio-ffmpeg
|
| 10 |
opencv-python
|
| 11 |
torchao==0.11.0
|
|
|
|
|
|
| 9 |
imageio-ffmpeg
|
| 10 |
opencv-python
|
| 11 |
torchao==0.11.0
|
| 12 |
+
uuid
|