alexander00001 commited on
Commit
740dcb4
·
verified ·
1 Parent(s): d8a2611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -38
app.py CHANGED
@@ -43,10 +43,10 @@ STYLE_PRESETS = {
43
  "Artistic": "artistic style, creative composition, unique visual style, expressive animation, stylized rendering"
44
  }
45
 
46
- # 固定模型配置 - 使用您的私人NSFW版本
47
- NSFW_CHECKPOINT_URL = "https://huggingface.co/alexander00001/NSFW_Wan_14b/resolve/main/nsfw_wan_14B_e15.safetensors"
48
- # 使用CogVideoX作为基础配置,因为Wan很可能基于CogVideoX架构
49
- BASE_CONFIG_MODEL = "THUDM/CogVideoX-5b" # 用于获取配置信息
50
 
51
  # 质量增强提示词 - 适配视频
52
  QUALITY_ENHANCERS = [
@@ -116,49 +116,43 @@ def initialize_model():
116
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
117
  print(f"🖥️ Using device: {device}")
118
 
119
- print(f"📦 Loading NSFW Wan T2V checkpoint: wan_14B_e15.safetensors")
120
- print(f"🔧 Using CogVideoX config from: {BASE_CONFIG_MODEL}")
121
 
122
- # 方法1: 尝试使用CogVideoXPipeline加载(最可能成功)
123
  try:
124
- from diffusers import CogVideoXPipeline
125
- pipeline = CogVideoXPipeline.from_single_file(
126
- NSFW_CHECKPOINT_URL,
127
- config=BASE_CONFIG_MODEL,
128
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
129
  use_safetensors=True,
130
- safety_checker=None,
131
- requires_safety_checker=False
132
  )
133
- print("Successfully loaded with CogVideoXPipeline.from_single_file()")
134
- except Exception as cogvideo_error:
135
- print(f"⚠️ CogVideoX loading failed: {cogvideo_error}")
136
 
137
- # 方法2: 尝试通用DiffusionPipeline
 
 
 
 
138
  try:
139
- pipeline = DiffusionPipeline.from_single_file(
140
- NSFW_CHECKPOINT_URL,
141
- config=BASE_CONFIG_MODEL,
142
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
143
- use_safetensors=True,
144
- safety_checker=None,
145
- requires_safety_checker=False,
146
- trust_remote_code=True
147
  )
148
- print(" Successfully loaded with DiffusionPipeline.from_single_file()")
149
- except Exception as diffusion_error:
150
- print(f"⚠️ DiffusionPipeline single file loading failed: {diffusion_error}")
151
-
152
- # 方法3: 最后备选 - 直接使用官方CogVideoX(非NSFW)
153
- print("🔄 Falling back to official CogVideoX model (non-NSFW)...")
154
  pipeline = CogVideoXPipeline.from_pretrained(
155
- BASE_CONFIG_MODEL,
156
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
157
- use_safetensors=True,
158
- safety_checker=None,
159
- requires_safety_checker=False
160
  )
161
- print("Loaded official CogVideoX as fallback (non-NSFW version)")
162
 
163
  pipeline = pipeline.to(device)
164
 
@@ -868,9 +862,9 @@ def create_interface():
868
  # ===== 启动应用 =====
869
  if __name__ == "__main__":
870
  print("🎬 Starting NSFW Video Generator...")
871
- print(f"🔧 NSFW Checkpoint: {NSFW_CHECKPOINT_URL}")
872
- print(f"🔧 Base Config: {BASE_CONFIG_MODEL} (CogVideoX-5b)")
873
- print("🔧 Using CogVideoXPipeline.from_single_file() method")
874
  print(f"🔧 Default Duration: {VIDEO_CONFIG['default_duration']}s")
875
  print(f"🔧 Default Resolution: {VIDEO_CONFIG['default_width']}×{VIDEO_CONFIG['default_height']}")
876
  print(f"🔧 Spaces GPU: {'✅ Available' if SPACES_AVAILABLE else '❌ Not Available'}")
 
43
  "Artistic": "artistic style, creative composition, unique visual style, expressive animation, stylized rendering"
44
  }
45
 
46
+ # 固定模型配置 - 使用您的完整私人仓库(添加配置文件后)
47
+ PRIVATE_MODEL = "alexander00001/NSFW_Wan_14b"
48
+ # 备用官方模型
49
+ FALLBACK_MODEL = "THUDM/CogVideoX-5b"
50
 
51
  # 质量增强提示词 - 适配视频
52
  QUALITY_ENHANCERS = [
 
116
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
117
  print(f"🖥️ Using device: {device}")
118
 
119
+ print(f"Loading Private NSFW Model: {PRIVATE_MODEL}")
120
+ print(f"Fallback Model: {FALLBACK_MODEL}")
121
 
122
+ # 首先尝试加载您的私人NSFW模型(完整仓库结构)
123
  try:
124
+ # 使用WanPipeline而不是CogVideoXPipeline
125
+ from diffusers import WanPipeline
126
+ pipeline = WanPipeline.from_pretrained(
127
+ PRIVATE_MODEL,
128
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
129
  use_safetensors=True,
130
+ trust_remote_code=True # 私人仓库需要
 
131
  )
132
+ print("Successfully loaded private NSFW Wan model!")
 
 
133
 
134
+ except Exception as private_error:
135
+ print(f"Private Wan model loading failed: {private_error}")
136
+ print(f"Falling back to official model: {FALLBACK_MODEL}")
137
+
138
+ # 备选:尝试官方Wan2.2-Diffusers版本
139
  try:
140
+ pipeline = WanPipeline.from_pretrained(
141
+ "Wan-AI/Wan2.2-T2V-A14B-Diffusers",
 
142
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
143
+ use_safetensors=True
 
 
 
144
  )
145
+ print("Loaded official Wan2.2-Diffusers model")
146
+ except Exception as wan_error:
147
+ print(f"Official Wan loading failed: {wan_error}")
148
+ # 最后备选:CogVideoX
149
+ from diffusers import CogVideoXPipeline
 
150
  pipeline = CogVideoXPipeline.from_pretrained(
151
+ FALLBACK_MODEL,
152
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
153
+ use_safetensors=True
 
 
154
  )
155
+ print("Loaded CogVideoX as final fallback")
156
 
157
  pipeline = pipeline.to(device)
158
 
 
862
  # ===== 启动应用 =====
863
  if __name__ == "__main__":
864
  print("🎬 Starting NSFW Video Generator...")
865
+ print(f"Private NSFW Model: {PRIVATE_MODEL}")
866
+ print(f"Fallback Model: {FALLBACK_MODEL}")
867
+ print("Using complete repository structure for proper loading")
868
  print(f"🔧 Default Duration: {VIDEO_CONFIG['default_duration']}s")
869
  print(f"🔧 Default Resolution: {VIDEO_CONFIG['default_width']}×{VIDEO_CONFIG['default_height']}")
870
  print(f"🔧 Spaces GPU: {'✅ Available' if SPACES_AVAILABLE else '❌ Not Available'}")