alexander00001 commited on
Commit
d933597
·
verified ·
1 Parent(s): 5d8672f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -39
app.py CHANGED
@@ -44,8 +44,9 @@ STYLE_PRESETS = {
44
  }
45
 
46
  # 固定模型配置 - 使用NSFW版本的safetensors文件
47
- FIXED_MODEL = "https://huggingface.co/NSFW-API/NSFW_Wan_14b/resolve/main/wan_14B_e15.safetensors"
48
- BASE_CONFIG_MODEL = "Wan-AI/Wan2.1-T2V-14B" # 用于获取配置信息
 
49
 
50
  # 质量增强提示词 - 适配视频
51
  QUALITY_ENHANCERS = [
@@ -116,46 +117,48 @@ def initialize_model():
116
  print(f"🖥️ Using device: {device}")
117
 
118
  print(f"📦 Loading NSFW Wan T2V checkpoint: wan_14B_e15.safetensors")
119
- print(f"🔧 Using config from: {BASE_CONFIG_MODEL}")
120
 
121
- # 使用from_single_file方法加载NSFW检查点
122
  try:
123
- from diffusers import WanPipeline
124
- pipeline = WanPipeline.from_single_file(
125
- FIXED_MODEL,
126
- config=BASE_CONFIG_MODEL, # 使用官方配置
127
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
128
  use_safetensors=True,
129
  safety_checker=None,
130
  requires_safety_checker=False
131
  )
132
- print("✅ Successfully loaded with WanPipeline.from_single_file()")
133
- except ImportError:
134
- # 如果WanPipeline不可用,使用通用DiffusionPipeline
135
- print("⚠️ WanPipeline not found, trying DiffusionPipeline")
136
- pipeline = DiffusionPipeline.from_single_file(
137
- FIXED_MODEL,
138
- config=BASE_CONFIG_MODEL, # 使用官方配置
139
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
140
- use_safetensors=True,
141
- safety_checker=None,
142
- requires_safety_checker=False,
143
- trust_remote_code=True
144
- )
145
- print("✅ Successfully loaded with DiffusionPipeline.from_single_file()")
146
- except Exception as single_file_error:
147
- # 最后备选:尝试直接从官方模型仓库加载(但这不是NSFW版本)
148
- print(f"⚠️ Single file loading failed: {single_file_error}")
149
- print("🔄 Falling back to official model repository...")
150
- pipeline = DiffusionPipeline.from_pretrained(
151
- BASE_CONFIG_MODEL,
152
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
153
- use_safetensors=True,
154
- safety_checker=None,
155
- requires_safety_checker=False,
156
- trust_remote_code=True
157
- )
158
- print("✅ Loaded official model as fallback")
 
 
159
 
160
  pipeline = pipeline.to(device)
161
 
@@ -635,7 +638,7 @@ def create_interface():
635
  # 简化警告信息
636
  gr.HTML('''
637
  <div class="warning-box">
638
- ⚠️ 18+ CONTENT WARNING ⚠️ | T2V Model: NSFW_Wan_14b (wan_14B_e15.safetensors)
639
  </div>
640
  ''')
641
 
@@ -863,9 +866,9 @@ def create_interface():
863
  # ===== 启动应用 =====
864
  if __name__ == "__main__":
865
  print("🎬 Starting NSFW Video Generator...")
866
- print(f"🔧 NSFW Wan T2V Checkpoint: wan_14B_e15.safetensors")
867
- print(f"🔧 Base Config Model: {BASE_CONFIG_MODEL}")
868
- print("🔧 Using from_single_file() method for NSFW checkpoint")
869
  print(f"🔧 Default Duration: {VIDEO_CONFIG['default_duration']}s")
870
  print(f"🔧 Default Resolution: {VIDEO_CONFIG['default_width']}×{VIDEO_CONFIG['default_height']}")
871
  print(f"🔧 Spaces GPU: {'✅ Available' if SPACES_AVAILABLE else '❌ Not Available'}")
 
44
  }
45
 
46
  # 固定模型配置 - 使用NSFW版本的safetensors文件
47
+ NSFW_CHECKPOINT_URL = "https://huggingface.co/NSFW-API/NSFW_Wan_14b/resolve/main/wan_14B_e15.safetensors"
48
+ # 使用CogVideoX作为基础配置,因为Wan很可能基于CogVideoX架构
49
+ BASE_CONFIG_MODEL = "THUDM/CogVideoX-5b" # 用于获取配置信息
50
 
51
  # 质量增强提示词 - 适配视频
52
  QUALITY_ENHANCERS = [
 
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
 
 
638
  # 简化警告信息
639
  gr.HTML('''
640
  <div class="warning-box">
641
+ ⚠️ 18+ CONTENT WARNING ⚠️ | Model: NSFW_Wan_14b → CogVideoX Architecture
642
  </div>
643
  ''')
644
 
 
866
  # ===== 启动应用 =====
867
  if __name__ == "__main__":
868
  print("🎬 Starting NSFW Video Generator...")
869
+ print(f"🔧 NSFW Checkpoint: {NSFW_CHECKPOINT_URL}")
870
+ print(f"🔧 Base Config: {BASE_CONFIG_MODEL} (CogVideoX-5b)")
871
+ print("🔧 Using CogVideoXPipeline.from_single_file() method")
872
  print(f"🔧 Default Duration: {VIDEO_CONFIG['default_duration']}s")
873
  print(f"🔧 Default Resolution: {VIDEO_CONFIG['default_width']}×{VIDEO_CONFIG['default_height']}")
874
  print(f"🔧 Spaces GPU: {'✅ Available' if SPACES_AVAILABLE else '❌ Not Available'}")