Spaces:
Running
on
Zero
Running
on
Zero
Update app_fast.py
Browse files- app_fast.py +69 -0
app_fast.py
CHANGED
|
@@ -11,6 +11,72 @@ import random
|
|
| 11 |
|
| 12 |
MODEL_ID = "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers"
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
#MODEL_ID ="linoyts/Wan2.2-VACE-Fun-14B-diffusers"
|
| 15 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 16 |
|
|
@@ -132,6 +198,9 @@ def generate_video(input_image, prompt, height, width, negative_prompt=default_n
|
|
| 132 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 133 |
print("prompt is")
|
| 134 |
print(prompt)
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if input_image is not None:
|
| 137 |
resized_image = input_image.resize((target_w, target_h))
|
|
|
|
| 11 |
|
| 12 |
MODEL_ID = "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers"
|
| 13 |
|
| 14 |
+
HF_MODEL = os.environ.get("HF_UPLOAD_REPO", "rahul7star/wan22TITV5B-image-analysis")
|
| 15 |
+
|
| 16 |
+
def upload_image_and_prompt(input_image, prompt_text) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Upload an image and a prompt text to Hugging Face Hub in a date-based folder.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
input_image (PIL.Image.Image or path-like): The image to upload.
|
| 22 |
+
prompt_text (str): Text prompt or summary associated with the image.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
str: Hugging Face folder path where the image and prompt were uploaded.
|
| 26 |
+
"""
|
| 27 |
+
import tempfile
|
| 28 |
+
import os
|
| 29 |
+
import uuid
|
| 30 |
+
from datetime import datetime
|
| 31 |
+
from huggingface_hub import upload_file
|
| 32 |
+
|
| 33 |
+
# Create a date-based folder on HF
|
| 34 |
+
today_str = datetime.now().strftime("%Y-%m-%d")
|
| 35 |
+
unique_subfolder = f"Upload-Image-{uuid.uuid4().hex[:8]}"
|
| 36 |
+
hf_folder = f"{today_str}/{unique_subfolder}"
|
| 37 |
+
|
| 38 |
+
# Save the image temporarily
|
| 39 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_img:
|
| 40 |
+
if isinstance(input_image, str):
|
| 41 |
+
# If path provided, just copy
|
| 42 |
+
import shutil
|
| 43 |
+
shutil.copy(input_image, tmp_img.name)
|
| 44 |
+
else:
|
| 45 |
+
# PIL.Image.Image
|
| 46 |
+
input_image.save(tmp_img.name, format="PNG")
|
| 47 |
+
tmp_img_path = tmp_img.name
|
| 48 |
+
|
| 49 |
+
# Upload image
|
| 50 |
+
image_filename = "input_image.png"
|
| 51 |
+
image_hf_path = f"{hf_folder}/{image_filename}"
|
| 52 |
+
upload_file(
|
| 53 |
+
path_or_fileobj=tmp_img_path,
|
| 54 |
+
path_in_repo=image_hf_path,
|
| 55 |
+
repo_id=HF_MODEL,
|
| 56 |
+
repo_type="model",
|
| 57 |
+
token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Upload prompt as summary.txt
|
| 61 |
+
summary_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
|
| 62 |
+
with open(summary_file, "w", encoding="utf-8") as f:
|
| 63 |
+
f.write(prompt_text)
|
| 64 |
+
summary_hf_path = f"{hf_folder}/summary.txt"
|
| 65 |
+
upload_file(
|
| 66 |
+
path_or_fileobj=summary_file,
|
| 67 |
+
path_in_repo=summary_hf_path,
|
| 68 |
+
repo_id=HF_MODEL,
|
| 69 |
+
repo_type="model",
|
| 70 |
+
token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Cleanup
|
| 74 |
+
os.remove(tmp_img_path)
|
| 75 |
+
os.remove(summary_file)
|
| 76 |
+
|
| 77 |
+
return hf_folder
|
| 78 |
+
|
| 79 |
+
|
| 80 |
#MODEL_ID ="linoyts/Wan2.2-VACE-Fun-14B-diffusers"
|
| 81 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 82 |
|
|
|
|
| 198 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 199 |
print("prompt is")
|
| 200 |
print(prompt)
|
| 201 |
+
# After generating or receiving input image
|
| 202 |
+
hf_folder = upload_image_and_prompt(input_image, prompt)
|
| 203 |
+
|
| 204 |
|
| 205 |
if input_image is not None:
|
| 206 |
resized_image = input_image.resize((target_w, target_h))
|