File size: 1,926 Bytes
a2b30b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

Title: Face Swapping with InsightFace

Description:

This Python application utilizes Hugging Face's InsightFace library to swap faces between two images. It leverages pre-trained models for face detection and face swapping, allowing for easy experimentation.

Features:

    Detects faces in two separate images.
    Swaps the detected faces between the images.
    Optionally displays the original and swapped images for visual verification.

Requirements:

    Python (tested with version 3.x)
    Hugging Face Transformers library
    InsightFace library (installable via pip install insightface)
    OpenCV-Python (for image processing)
    matplotlib (for plotting)
    NumPy (for numerical operations)

Installation:

    Create a virtual environment (recommended) to isolate project dependencies.

    Install the required libraries using pip:
    Bash

    pip install -r requirements.txt

    Usa el c贸digo con precauci贸n.

    Note: Create a requirements.txt file in your project directory with the list of requirements mentioned above.

Usage:

    Save two images (image1.jpg and image2.jpg) in the same directory as your script (app.py).

    Run the script from the terminal:
    Bash

    python app.py

    Usa el c贸digo con precauci贸n.

Explanation of the Code (app.py):

The provided code defines functions for:

    Initializing the FaceAnalysis application and face swapper model.
    Reading images and detecting faces.
    Swapping faces and optionally displaying the results.

Further Customization:

    Modify the swap_n_show function to customize the plotting behavior or add functionalities like saving the swapped images.
    Explore other functionalities offered by InsightFace for advanced face manipulation tasks.

Contributing:

Feel free to submit pull requests for bug fixes or improvements to this code.

License:

[Specify the license you want to use for your code, e.g., MIT License]