File size: 4,908 Bytes
8209de3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3e01fc
8209de3
 
 
 
b3e01fc
8209de3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
language:
- en
tags:
- FaceSwap
- Headshot
- SmoothChange
- FaceChange
- SmoothSwap
- SwapFace
- FaceEditing

license: apache-2.0
---
# FaceSwap - AI-Powered Headshot Generator

**FaceSwap** is a flow designed to seamlessly swap faces between two images. This project is built on top of ComfyUI, a modular and flexible interface that enables easy integration and customization of AI workflows. By leveraging advanced facial recognition and manipulation technologies, FaceSwap allows users to replace one face with another in images.

FaceSwap utilizes models to detect key facial landmarks, map them to the target face, and generate a realistic face swap by considering aspects like lighting, expression, and pose. This flow is designed to provide an easy-to-use interface through ComfyUI, allowing users to swap faces effortlessly with minimal setup.

<div align="center">
  <img width="500" height="500" alt="foduucom/FaceSwap" src="https://huggingface.co/foduucom/Headshot_Generator-FaceSwap/resolve/main/display.png">
</div>

## Requirements

To run **FaceSwap**, you'll need to install **ComfyUI** and set up a few dependencies. Follow the steps below for installation and setup.

### Prerequisites
- **Python 3.9 or higher** (Ensure Python 3.9+ is installed on your machine)
- **NVIDIA GPU** (Recommended for faster processing, though CPU can also be used)

---

## Step-by-Step Installation

1. Clone the ComfyUI Repository
Start by cloning the main ComfyUI repository:

```bash
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
```

2. Install Dependencies
Install all the required dependencies for ComfyUI:

```bash
pip install -r requirements.txt
```

3. Install **ComfyUI-Manager**
To manage custom nodes, you'll need to install ComfyUI-Manager. Run the following commands inside the **ComfyUI/custom_nodes** directory:

```bash
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
```

After cloning the ComfyUI-Manager, **restart ComfyUI**.

4. Install **Reactor Node for ComfyUI** by clicking on Manager -> Custom Nodes Manage
<div align="center">
  <img width="600" height="500" alt="foduucom/FaceSwap" src="https://huggingface.co/foduucom/Headshot_Generator-FaceSwap/resolve/main/node.png">
</div>

or you can clone the repository in the directory **ComfyUI/custom_nodes**
```bash
git clone https://github.com/Gourieff/comfyui-reactor-node.git
```

5. Download Pre-trained Models
Download **inswapper_128.onnx** and place the downloaded model in the ComfyUI/models/insightface/ directory

Note: If directory don't exist, create them manually.

4. Start ComfyUI
Run ComfyUI by executing the following command:

```bash
python3 FaceSwap.py
```
This will start ComfyUI, and you can access the interface by navigating to http://127.0.0.1:8188 in your browser.

## Setting Up and Using the FaceSwap Workflow

1. Clone the Headshot_Generator-FaceSwap Repository
Clone this repository that contains the FaceSwap workflow and assets:

```bash
git clone https://huggingface.co/foduucom/Headshot_Generator-FaceSwap
cd Headshot_Generator-FaceSwap
```

2. How to use
Once ComfyUI is running, open the browser window (default: http://127.0.0.1:8188), and follow these steps:

- Click on the **Load button** in the menu bar and select the **workflow.json** file from this repo you just cloned.
- Upload the **Workflow.json** to start the face-swapping process.
- Provide Input Images
  - **Source Image:** The image containing the face you want to swap.
  - **Target Image:** The image where the face will be swapped into.
- Click **Queue Prompt** to initiate the face-swapping process. The AI model will process the images and generate the output.

or you can use by python script provided in this repository:
```bash 
python3 FaceSwap.py

#Remember change the input paths in script here :
#prompt["1"]["inputs"]["image"] = "//put your input image"
#prompt["2"]["inputs"]["image"] = "//put your source face image"

```

## Troubleshooting
- ComfyUI Not Running: Ensure that all dependencies are installed correctly and that you’re using Python 3.9 or higher. If issues persist, check the ComfyUI GitHub repository for troubleshooting guides.

- Missing Models: Ensure you’ve downloaded the required models (sam_vit_h_4b8939.pth and groundingdino_swint_ogc.pth) and placed them in the correct directories (ComfyUI/models/sams/ and ComfyUI/models/grounding-dino/).

## Slow Performance: 
Using a GPU is highly recommended for better performance. If you’re using a CPU, the processing time may be longer.

## Compute Infrastructure

## Hardware

NVIDIA GeForce RTX 3060 card

## Model Card Contact

For inquiries and contributions, please contact us at [email protected].

```bibtex
@ModelCard{
  author    = {Nehul Agrawal and
               Priyal Mehta},
  title     = {FaceSwap - AI-Powered Face Swap / Headshot Generator},
  year      = {2024}
}
```