modelslab-deepfake
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseModelsLab Deepfake & Face Swap
ModelsLab 深度伪造与换脸
Swap faces in images and videos using advanced AI-powered deepfake technology.
借助先进的AI驱动深度伪造技术,完成图片和视频中的人脸互换。
When to Use This Skill
适用场景
- Swap faces in photos
- Replace faces in videos
- Create personalized video content
- Generate character variations
- Build face swap applications
- Create entertainment content
- 替换照片中的人脸
- 替换视频中的人脸
- 创建个性化视频内容
- 生成角色变体
- 搭建换脸应用
- 制作娱乐内容
Available Endpoints
可用接口
Image Face Swap
图片换脸
- Specific Face Swap:
POST https://modelslab.com/api/v6/deepfake/specific_face_swap - Multiple Face Swap:
POST https://modelslab.com/api/v6/deepfake/multiple_face_swap
- 指定人脸替换:
POST https://modelslab.com/api/v6/deepfake/specific_face_swap - 批量人脸替换:
POST https://modelslab.com/api/v6/deepfake/multiple_face_swap
Video Face Swap
视频换脸
- Single Video Swap:
POST https://modelslab.com/api/v6/deepfake/single_video_swap - Specific Video Swap:
POST https://modelslab.com/api/v6/deepfake/specific_video_swap
- 全视频人脸替换:
POST https://modelslab.com/api/v6/deepfake/single_video_swap - 指定视频人脸替换**:
POST https://modelslab.com/api/v6/deepfake/specific_video_swap
Specific Face Swap (Image)
指定图片人脸替换
python
import requests
def swap_face(target_image, face_to_use, api_key):
"""Swap a face in an image.
Args:
target_image: URL of the image containing face to replace
face_to_use: URL of the image with face to swap in
api_key: Your ModelsLab API key
Returns:
URL of the face-swapped image
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/specific_face_swap",
json={
"key": api_key,
"init_image": target_image,
"target_image": face_to_use
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
else:
raise Exception(f"Error: {data.get('message', 'Unknown error')}")python
import requests
def swap_face(target_image, face_to_use, api_key):
"""替换图片中的人脸。
参数:
target_image: 包含待替换人脸的图片URL
face_to_use: 用于替换的人脸图片URL
api_key: 你的ModelsLab API密钥
返回:
换脸后的图片URL
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/specific_face_swap",
json={
"key": api_key,
"init_image": target_image,
"target_image": face_to_use
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
else:
raise Exception(f"错误: {data.get('message', '未知错误')}")Usage
使用示例
result = swap_face(
"https://example.com/target-photo.jpg", # Photo to modify
"https://example.com/face-to-swap.jpg", # Face to insert
"your_api_key"
)
print(f"Face swapped image: {result}")
undefinedresult = swap_face(
"https://example.com/target-photo.jpg", # 待修改的照片
"https://example.com/face-to-swap.jpg", # 要插入的人脸
"your_api_key"
)
print(f"换脸后的图片: {result}")
undefinedMultiple Face Swap (Image)
批量图片人脸替换
python
def swap_multiple_faces(image_with_faces, face_to_use, api_key):
"""Swap all faces in an image with the same face.
Args:
image_with_faces: URL of image with multiple faces
face_to_use: URL of face to swap in
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/multiple_face_swap",
json={
"key": api_key,
"init_image": image_with_faces,
"target_image": face_to_use
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
else:
raise Exception(data.get("message"))python
def swap_multiple_faces(image_with_faces, face_to_use, api_key):
"""将图片中所有人脸替换为同一张人脸。
参数:
image_with_faces: 包含多个人脸的图片URL
face_to_use: 用于替换的人脸图片URL
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/multiple_face_swap",
json={
"key": api_key,
"init_image": image_with_faces,
"target_image": face_to_use
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
else:
raise Exception(data.get("message"))Swap all faces in group photo
替换合影中的所有人脸
result = swap_multiple_faces(
"https://example.com/group-photo.jpg",
"https://example.com/celebrity-face.jpg",
"your_api_key"
)
undefinedresult = swap_multiple_faces(
"https://example.com/group-photo.jpg",
"https://example.com/celebrity-face.jpg",
"your_api_key"
)
undefinedSingle Video Face Swap
全视频人脸替换
python
import time
def swap_video_faces(video_url, face_image, api_key, output_format="mp4"):
"""Swap all faces in a video.
Args:
video_url: URL of the video
face_image: URL of face to swap in
output_format: "mp4" or "gif"
Returns:
URL of the face-swapped video
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/single_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": face_image,
"output_format": output_format,
"watermark": False # Set to True for watermark
}
)
data = response.json()
if data["status"] == "error":
raise Exception(f"Error: {data['message']}")
if data["status"] == "success":
return data["output"][0]
# Video processing is async
request_id = data["id"]
print(f"Video processing... Request ID: {request_id}")
return poll_deepfake_result(request_id, api_key)
def poll_deepfake_result(request_id, api_key, timeout=900):
"""Poll for video face swap results."""
start_time = time.time()
while time.time() - start_time < timeout:
fetch = requests.post(
f"https://modelslab.com/api/v6/deepfake/fetch/{request_id}",
json={"key": api_key}
)
result = fetch.json()
if result["status"] == "success":
return result["output"][0]
elif result["status"] == "failed":
raise Exception(result.get("message", "Failed"))
print(f"Processing... ({int(time.time() - start_time)}s)")
time.sleep(10)
raise Exception("Timeout")python
import time
def swap_video_faces(video_url, face_image, api_key, output_format="mp4"):
"""替换视频中所有人脸。
参数:
video_url: 视频URL
face_image: 用于替换的人脸图片URL
output_format: 输出格式,可选"mp4"或"gif"
返回:
换脸后的视频URL
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/single_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": face_image,
"output_format": output_format,
"watermark": False # 设置为True添加水印
}
)
data = response.json()
if data["status"] == "error":
raise Exception(f"错误: {data['message']}")
if data["status"] == "success":
return data["output"][0]
# 视频处理为异步操作
request_id = data["id"]
print(f"视频处理中... 请求ID: {request_id}")
return poll_deepfake_result(request_id, api_key)
def poll_deepfake_result(request_id, api_key, timeout=900):
"""轮询视频换脸结果。"""
start_time = time.time()
while time.time() - start_time < timeout:
fetch = requests.post(
f"https://modelslab.com/api/v6/deepfake/fetch/{request_id}",
json={"key": api_key}
)
result = fetch.json()
if result["status"] == "success":
return result["output"][0]
elif result["status"] == "failed":
raise Exception(result.get("message", "处理失败"))
print(f"处理中... ({int(time.time() - start_time)}秒)")
time.sleep(10)
raise Exception("处理超时")Usage
使用示例
swapped_video = swap_video_faces(
"https://example.com/video.mp4",
"https://example.com/face.jpg",
"your_api_key"
)
print(f"Face-swapped video: {swapped_video}")
undefinedswapped_video = swap_video_faces(
"https://example.com/video.mp4",
"https://example.com/face.jpg",
"your_api_key"
)
print(f"换脸后的视频: {swapped_video}")
undefinedSpecific Video Face Swap
指定视频人脸替换
python
def swap_specific_video_face(video_url, new_face, reference_face, api_key):
"""Swap a specific face in a video (when multiple faces present).
Args:
video_url: URL of the video
new_face: URL of the face to swap in
reference_face: URL of the specific face to replace
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/specific_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": new_face,
"source_image": reference_face,
"output_format": "mp4",
"watermark": False
}
)
data = response.json()
if data["status"] == "processing":
return poll_deepfake_result(data["id"], api_key)
elif data["status"] == "success":
return data["output"][0]
else:
raise Exception(data.get("message"))python
def swap_specific_video_face(video_url, new_face, reference_face, api_key):
"""替换视频中指定的人脸(视频包含多个人脸时使用)。
参数:
video_url: 视频URL
new_face: 用于替换的人脸图片URL
reference_face: 待替换的指定人脸图片URL
"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/specific_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": new_face,
"source_image": reference_face,
"output_format": "mp4",
"watermark": False
}
)
data = response.json()
if data["status"] == "processing":
return poll_deepfake_result(data["id"], api_key)
elif data["status"] == "success":
return data["output"][0]
else:
raise Exception(data.get("message"))Swap only one person's face in multi-person video
替换多人视频中某一个人的人脸
result = swap_specific_video_face(
"https://example.com/interview.mp4",
"https://example.com/new-face.jpg",
"https://example.com/face-to-replace.jpg",
"your_api_key"
)
undefinedresult = swap_specific_video_face(
"https://example.com/interview.mp4",
"https://example.com/new-face.jpg",
"https://example.com/face-to-replace.jpg",
"your_api_key"
)
undefinedUsing Webhooks
使用Webhook
python
def deepfake_with_webhook(video_url, face_image, api_key, webhook_url, track_id):
"""Process video face swap with webhook notification."""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/single_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": face_image,
"output_format": "mp4",
"webhook": webhook_url,
"track_id": track_id
}
)
data = response.json()
print(f"Request submitted: {data['id']}")
return data["id"]python
def deepfake_with_webhook(video_url, face_image, api_key, webhook_url, track_id):
"""通过Webhook通知处理视频换脸。"""
response = requests.post(
"https://modelslab.com/api/v6/deepfake/single_video_swap",
json={
"key": api_key,
"init_video": video_url,
"target_image": face_image,
"output_format": "mp4",
"webhook": webhook_url,
"track_id": track_id
}
)
data = response.json()
print(f"请求已提交: {data['id']}")
return data["id"]Usage
使用示例
request_id = deepfake_with_webhook(
"https://example.com/video.mp4",
"https://example.com/face.jpg",
"your_api_key",
"https://yourserver.com/webhook/deepfake",
"video_001"
)
undefinedrequest_id = deepfake_with_webhook(
"https://example.com/video.mp4",
"https://example.com/face.jpg",
"your_api_key",
"https://yourserver.com/webhook/deepfake",
"video_001"
)
undefinedKey Parameters
关键参数
| Parameter | Description | Values |
|---|---|---|
| Target image to modify | Image URL |
| Target video to modify | Video URL |
| Face to swap in | Image URL with clear face |
| Specific face to replace | Image URL (for specific swap) |
| Video output format | |
| Add watermark | |
| Async callback URL | Your server endpoint |
| Request identifier | Unique tracking ID |
| 参数 | 说明 | 取值 |
|---|---|---|
| 待修改的目标图片 | 图片URL |
| 待修改的目标视频 | 视频URL |
| 用于替换的人脸 | 清晰人脸的图片URL |
| 待替换的指定人脸 | 图片URL(仅指定换脸时使用) |
| 视频输出格式 | |
| 是否添加水印 | |
| 异步回调URL | 你的服务器端点 |
| 请求标识符 | 唯一跟踪ID |
Best Practices
最佳实践
1. Use High-Quality Face Images
1. 使用高质量人脸图片
✓ Good: Clear, well-lit frontal face photo
✓ Good: High resolution (at least 512x512)
✓ Good: Neutral expression works best
✗ Avoid: Blurry or low-resolution images
✗ Avoid: Extreme angles or profiles
✗ Avoid: Heavy shadows or poor lighting✓ 推荐: 清晰、光线充足的正面人脸照片
✓ 推荐: 高分辨率(至少512x512)
✓ 推荐: 中性表情效果最佳
✗ 避免: 模糊或低分辨率图片
✗ 避免: 极端角度或侧面照
✗ 避免: 阴影过重或光线不足2. Video Face Swap Requirements
2. 视频换脸要求
- Clear, visible faces in the video
- Good lighting conditions
- Frontal or near-frontal angles work best
- Shorter videos process faster
- 视频中的人脸清晰可见
- 光线条件良好
- 正面或接近正面的角度效果最佳
- 视频越短处理速度越快
3. Handle Async Operations
3. 处理异步操作
python
undefinedpython
undefinedVideo face swaps are ALWAYS async
视频换脸始终为异步操作
if data["status"] == "processing":
result = poll_deepfake_result(data["id"], api_key)
undefinedif data["status"] == "processing":
result = poll_deepfake_result(data["id"], api_key)
undefined4. Set Appropriate Timeouts
4. 设置合理超时时间
python
undefinedpython
undefinedVideo processing takes time
视频处理需要时间
poll_deepfake_result(request_id, api_key, timeout=900) # 15 minutes
undefinedpoll_deepfake_result(request_id, api_key, timeout=900) # 15分钟
undefined5. Use Webhooks for Long Videos
5. 长视频使用Webhook
python
undefinedpython
undefinedDon't poll for long videos, use webhooks
长视频不要轮询,使用Webhook
deepfake_with_webhook(video_url, face, api_key, webhook_url, track_id)
undefineddeepfake_with_webhook(video_url, face, api_key, webhook_url, track_id)
undefinedCommon Use Cases
常见应用场景
Profile Picture Generator
个人头像生成器
python
def create_profile_variations(base_photo, face_images, api_key):
"""Generate multiple profile picture variations."""
variations = []
for i, face in enumerate(face_images):
result = swap_face(base_photo, face, api_key)
variations.append(result)
print(f"Variation {i+1} created: {result}")
return variationspython
def create_profile_variations(base_photo, face_images, api_key):
"""生成多种个人头像变体。"""
variations = []
for i, face in enumerate(face_images):
result = swap_face(base_photo, face, api_key)
variations.append(result)
print(f"已生成变体 {i+1}: {result}")
return variationsCreate variations
生成头像变体
profiles = create_profile_variations(
"https://example.com/professional-photo.jpg",
[
"https://example.com/style1-face.jpg",
"https://example.com/style2-face.jpg",
"https://example.com/style3-face.jpg"
],
api_key
)
undefinedprofiles = create_profile_variations(
"https://example.com/professional-photo.jpg",
[
"https://example.com/style1-face.jpg",
"https://example.com/style2-face.jpg",
"https://example.com/style3-face.jpg"
],
api_key
)
undefinedVideo Personalization
视频个性化
python
def personalize_video(template_video, user_face, api_key):
"""Create personalized video with user's face."""
personalized = swap_video_faces(
template_video,
user_face,
api_key,
output_format="mp4"
)
print(f"Personalized video: {personalized}")
return personalizedpython
def personalize_video(template_video, user_face, api_key):
"""生成包含用户人脸的个性化视频。"""
personalized = swap_video_faces(
template_video,
user_face,
api_key,
output_format="mp4"
)
print(f"个性化视频: {personalized}")
return personalizedCreate custom greeting video
创建自定义问候视频
greeting = personalize_video(
"https://example.com/greeting-template.mp4",
"https://example.com/user-photo.jpg",
api_key
)
undefinedgreeting = personalize_video(
"https://example.com/greeting-template.mp4",
"https://example.com/user-photo.jpg",
api_key
)
undefinedCharacter Variations
角色变体生成
python
def generate_character_variations(character_image, face_options, api_key):
"""Generate different character variations."""
characters = []
for face in face_options:
char = swap_face(character_image, face, api_key)
characters.append(char)
return characterspython
def generate_character_variations(character_image, face_options, api_key):
"""生成不同的角色变体。"""
characters = []
for face in face_options:
char = swap_face(character_image, face, api_key)
characters.append(char)
return charactersGroup Photo Editing
合影编辑
python
undefinedpython
undefinedReplace one person in group photo
替换合影中某个人的人脸
edited_group_photo = swap_specific_video_face(
"https://example.com/group-video.mp4",
"https://example.com/replacement-face.jpg",
"https://example.com/person-to-replace.jpg",
api_key
)
undefinededited_group_photo = swap_specific_video_face(
"https://example.com/group-video.mp4",
"https://example.com/replacement-face.jpg",
"https://example.com/person-to-replace.jpg",
api_key
)
undefinedError Handling
错误处理
python
try:
result = swap_face(target, face, api_key)
print(f"Face swap successful: {result}")
except Exception as e:
print(f"Face swap failed: {e}")
# Check image quality, try different images, or notify userpython
try:
result = swap_face(target, face, api_key)
print(f"换脸成功: {result}")
except Exception as e:
print(f"换脸失败: {e}")
# 检查图片质量,尝试更换图片,或通知用户Performance Tips
性能优化技巧
- Use Webhooks: For videos, always use webhooks
- Optimize Face Images: Use clear, high-quality faces
- Batch Process: Submit multiple requests together
- Cache Results: Store generated content
- Monitor Processing Time: Track and optimize
- 使用Webhook:处理视频时优先使用Webhook
- 优化人脸图片:使用清晰、高质量的人脸图片
- 批量处理:批量提交多个请求
- 缓存结果:存储生成的内容
- 监控处理时间:跟踪并优化处理时长
Ethical Considerations
伦理考量
⚠️ Important: Use face swap technology responsibly
- Obtain consent before using someone's face
- Don't create misleading or harmful content
- Follow local laws and regulations
- Respect privacy and image rights
- Add disclaimers when sharing deepfake content
⚠️ 重要提示:请负责任地使用换脸技术
- 使用他人人脸前需获得同意
- 不要制作误导性或有害内容
- 遵守当地法律法规
- 尊重隐私和肖像权
- 分享深度伪造内容时添加免责声明
Enterprise API
企业版API
For dedicated resources:
python
undefined如需专属资源:
python
undefinedEnterprise endpoints
企业版接口
Resources
相关资源
- Deepfake API Docs: https://docs.modelslab.com/deepfake-api/overview
- Face Swap Image: https://docs.modelslab.com/deepfake-api/specific-face-swap
- Video Face Swap: https://docs.modelslab.com/deepfake-api/single-video-swap
- Get API Key: https://modelslab.com/dashboard
Related Skills
相关技能
- - Generate videos
modelslab-video-generation - - Handle async operations
modelslab-webhooks - - Use official SDKs
modelslab-sdk-usage
- - 视频生成
modelslab-video-generation - - 异步操作处理
modelslab-webhooks - - 官方SDK使用
modelslab-sdk-usage