Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,8 @@
|
|
| 16 |
|
| 17 |
import argparse
|
| 18 |
import os
|
|
|
|
|
|
|
| 19 |
|
| 20 |
import gradio as gr
|
| 21 |
import numpy as np
|
|
@@ -25,6 +27,49 @@ import torch
|
|
| 25 |
from diffnext.pipelines import URSAPipeline
|
| 26 |
from diffnext.utils import export_to_image, export_to_video
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Fix tokenizer fork issue.
|
| 29 |
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
| 30 |
# Switch to the allocator optimized for dynamic shape.
|
|
@@ -34,7 +79,7 @@ os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
|
| 34 |
def parse_args():
|
| 35 |
"""Parse arguments."""
|
| 36 |
parser = argparse.ArgumentParser(description="Serve URSA TI2V application")
|
| 37 |
-
parser.add_argument("--model", default="BAAI/URSA-0.
|
| 38 |
parser.add_argument("--device", type=int, default=0, help="device index")
|
| 39 |
parser.add_argument("--precision", default="float16", help="compute precision")
|
| 40 |
return parser.parse_args()
|
|
@@ -111,10 +156,10 @@ video_presets = {
|
|
| 111 |
|
| 112 |
prompts = [
|
| 113 |
"a lone grizzly bear walks through a misty forest at dawn, sunlight catching its fur.",
|
| 114 |
-
"Many spotted jellyfish pulsating under water. Their bodies are transparent and glowing in deep ocean.",
|
| 115 |
-
"An intense close-up of a soldier’s face, covered in dirt and sweat, his eyes filled with determination as he surveys the battlefield.",
|
| 116 |
-
"a close-up shot of a woman standing in a dimly lit room. she is wearing a traditional chinese outfit, which includes a red and gold dress with intricate designs and a matching headpiece. the woman has her hair styled in an updo, adorned with a gold accessory. her makeup is done in a way that accentuates her features, with red lipstick and dark eyeshadow. she is looking directly at the camera with a neutral expression. the room has a rustic feel, with wooden beams and a stone wall visible in the background. the lighting in the room is soft and warm, creating a contrast with the woman's vibrant attire. there are no texts or other objects in the video. the style of the video is a portrait, focusing on the woman and her attire.",
|
| 117 |
-
"The camera slowly rotates around a massive stack of vintage televisions that are placed within a large New York museum gallery. Each of the televisions is showing a different program. There are 1950s sci-fi movies with their distinctive visuals, horror movies with their creepy scenes, news broadcasts with moving images and words, static on some screens, and a 1970s sitcom with its characteristic look. The televisions are of various sizes and designs, some with rounded edges and others with more angular shapes. The gallery is well-lit, with light falling on the stack of televisions and highlighting the different programs being shown. There are no people visible in the immediate vicinity, only the stack of televisions and the surrounding gallery space.",
|
| 118 |
]
|
| 119 |
motion_scores = [9, 9, 9, 9, 9]
|
| 120 |
videos = ["", "", "", "", ""]
|
|
@@ -125,7 +170,12 @@ if __name__ == "__main__":
|
|
| 125 |
args = parse_args()
|
| 126 |
|
| 127 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu", args.device)
|
| 128 |
-
model_args = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
pipe = URSAPipeline.from_pretrained(args.model, **model_args).to(device)
|
| 130 |
|
| 131 |
# Application.
|
|
@@ -138,13 +188,13 @@ if __name__ == "__main__":
|
|
| 138 |
prompt = gr.Text(
|
| 139 |
label="Prompt",
|
| 140 |
placeholder="Describe the video you want to generate",
|
| 141 |
-
value="A lone grizzly bear walks through a misty forest at dawn, sunlight catching its fur.",
|
| 142 |
lines=5,
|
| 143 |
)
|
| 144 |
negative_prompt = gr.Text(
|
| 145 |
label="Negative Prompt",
|
| 146 |
placeholder="Describe what you don't want in the video",
|
| 147 |
-
value="worst quality, low quality, inconsistent motion, static, still, blurry, jittery, distorted, ugly",
|
| 148 |
lines=1,
|
| 149 |
)
|
| 150 |
with gr.Row():
|
|
@@ -158,7 +208,7 @@ if __name__ == "__main__":
|
|
| 158 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 159 |
guidance_scale = gr.Slider(label="Guidance scale", minimum=1, maximum=10.0, step=0.1, value=7.0)
|
| 160 |
with gr.Row():
|
| 161 |
-
num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
|
| 162 |
options.__exit__(), input_col.__exit__()
|
| 163 |
|
| 164 |
# Results.
|
|
@@ -201,4 +251,4 @@ if __name__ == "__main__":
|
|
| 201 |
],
|
| 202 |
outputs=[result, seed],
|
| 203 |
)
|
| 204 |
-
app.__exit__(), app.launch(share=False, ssr_mode=False, max_threads=1)
|
|
|
|
| 16 |
|
| 17 |
import argparse
|
| 18 |
import os
|
| 19 |
+
import sys
|
| 20 |
+
import types
|
| 21 |
|
| 22 |
import gradio as gr
|
| 23 |
import numpy as np
|
|
|
|
| 27 |
from diffnext.pipelines import URSAPipeline
|
| 28 |
from diffnext.utils import export_to_image, export_to_video
|
| 29 |
|
| 30 |
+
# =========================
|
| 31 |
+
# 🔧 关键补丁:修复 Qwen3Config 缺失 rope_theta
|
| 32 |
+
# =========================
|
| 33 |
+
def _patch_diffnext_qwen3():
|
| 34 |
+
"""
|
| 35 |
+
兼容 transformers 新版本中 Qwen3Config 没有 rope_theta 的问题
|
| 36 |
+
"""
|
| 37 |
+
try:
|
| 38 |
+
from diffnext.models.text_encoders import qwen3
|
| 39 |
+
except Exception:
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
orig_from_config = qwen3.Qwen3RotaryEmbedding.from_config
|
| 43 |
+
|
| 44 |
+
@classmethod
|
| 45 |
+
def patched_from_config(cls, config):
|
| 46 |
+
# ---- rope_theta ----
|
| 47 |
+
if not hasattr(config, "rope_theta"):
|
| 48 |
+
# 常见存放位置之一
|
| 49 |
+
rp = getattr(config, "rope_parameters", None)
|
| 50 |
+
if isinstance(rp, dict) and "rope_theta" in rp:
|
| 51 |
+
config.rope_theta = rp["rope_theta"]
|
| 52 |
+
else:
|
| 53 |
+
# URSA / Qwen3 常用默认值
|
| 54 |
+
config.rope_theta = float(1e6)
|
| 55 |
+
|
| 56 |
+
# ---- max_position_embeddings ----
|
| 57 |
+
if not hasattr(config, "max_position_embeddings"):
|
| 58 |
+
config.max_position_embeddings = int(
|
| 59 |
+
getattr(config, "max_seq_len", 2048)
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
return orig_from_config.__func__(cls, config)
|
| 63 |
+
|
| 64 |
+
qwen3.Qwen3RotaryEmbedding.from_config = patched_from_config
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
_patch_diffnext_qwen3()
|
| 68 |
+
# =========================
|
| 69 |
+
# 🔧 补丁结束
|
| 70 |
+
# =========================
|
| 71 |
+
|
| 72 |
+
|
| 73 |
# Fix tokenizer fork issue.
|
| 74 |
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
| 75 |
# Switch to the allocator optimized for dynamic shape.
|
|
|
|
| 79 |
def parse_args():
|
| 80 |
"""Parse arguments."""
|
| 81 |
parser = argparse.ArgumentParser(description="Serve URSA TI2V application")
|
| 82 |
+
parser.add_argument("--model", default="BAAI/URSA-0.6K-FSQ320", help="model path")
|
| 83 |
parser.add_argument("--device", type=int, default=0, help="device index")
|
| 84 |
parser.add_argument("--precision", default="float16", help="compute precision")
|
| 85 |
return parser.parse_args()
|
|
|
|
| 156 |
|
| 157 |
prompts = [
|
| 158 |
"a lone grizzly bear walks through a misty forest at dawn, sunlight catching its fur.",
|
| 159 |
+
"Many spotted jellyfish pulsating under water. Their bodies are transparent and glowing in deep ocean.",
|
| 160 |
+
"An intense close-up of a soldier’s face, covered in dirt and sweat, his eyes filled with determination as he surveys the battlefield.",
|
| 161 |
+
"a close-up shot of a woman standing in a dimly lit room. she is wearing a traditional chinese outfit, which includes a red and gold dress with intricate designs and a matching headpiece. the woman has her hair styled in an updo, adorned with a gold accessory. her makeup is done in a way that accentuates her features, with red lipstick and dark eyeshadow. she is looking directly at the camera with a neutral expression. the room has a rustic feel, with wooden beams and a stone wall visible in the background. the lighting in the room is soft and warm, creating a contrast with the woman's vibrant attire. there are no texts or other objects in the video. the style of the video is a portrait, focusing on the woman and her attire.",
|
| 162 |
+
"The camera slowly rotates around a massive stack of vintage televisions that are placed within a large New York museum gallery. Each of the televisions is showing a different program. There are 1950s sci-fi movies with their distinctive visuals, horror movies with their creepy scenes, news broadcasts with moving images and words, static on some screens, and a 1970s sitcom with its characteristic look. The televisions are of various sizes and designs, some with rounded edges and others with more angular shapes. The gallery is well-lit, with light falling on the stack of televisions and highlighting the different programs being shown. There are no people visible in the immediate vicinity, only the stack of televisions and the surrounding gallery space.",
|
| 163 |
]
|
| 164 |
motion_scores = [9, 9, 9, 9, 9]
|
| 165 |
videos = ["", "", "", "", ""]
|
|
|
|
| 170 |
args = parse_args()
|
| 171 |
|
| 172 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu", args.device)
|
| 173 |
+
model_args = {
|
| 174 |
+
"torch_dtype": getattr(torch, args.precision.lower()),
|
| 175 |
+
"trust_remote_code": True,
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
# ✅ 不再报 rope_theta 错
|
| 179 |
pipe = URSAPipeline.from_pretrained(args.model, **model_args).to(device)
|
| 180 |
|
| 181 |
# Application.
|
|
|
|
| 188 |
prompt = gr.Text(
|
| 189 |
label="Prompt",
|
| 190 |
placeholder="Describe the video you want to generate",
|
| 191 |
+
value="A lone grizzly bear walks through a misty forest at dawn, sunlight catching its fur.",
|
| 192 |
lines=5,
|
| 193 |
)
|
| 194 |
negative_prompt = gr.Text(
|
| 195 |
label="Negative Prompt",
|
| 196 |
placeholder="Describe what you don't want in the video",
|
| 197 |
+
value="worst quality, low quality, inconsistent motion, static, still, blurry, jittery, distorted, ugly",
|
| 198 |
lines=1,
|
| 199 |
)
|
| 200 |
with gr.Row():
|
|
|
|
| 208 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 209 |
guidance_scale = gr.Slider(label="Guidance scale", minimum=1, maximum=10.0, step=0.1, value=7.0)
|
| 210 |
with gr.Row():
|
| 211 |
+
num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
|
| 212 |
options.__exit__(), input_col.__exit__()
|
| 213 |
|
| 214 |
# Results.
|
|
|
|
| 251 |
],
|
| 252 |
outputs=[result, seed],
|
| 253 |
)
|
| 254 |
+
app.__exit__(), app.launch(share=False, ssr_mode=False, max_threads=1)
|