| | --- |
| | license: mit |
| | --- |
| | |
| | # Faceswap API |
| |
|
| | **Model Page:** [Faceswap API](https://piapi.ai/faceswap-api) |
| |
|
| | This model card illustartes the steps to use Faceswap API's endpoint. |
| | You can also check out other model cards: |
| |
|
| | - [Midjourney API](https://huggingface.co/PiAPI/Midjourney-API) |
| | - [Suno API](https://huggingface.co/PiAPI/Suno-API) |
| | - [Dream Machine API](https://huggingface.co/PiAPI/Dream-Machine-API) |
| |
|
| | **Model Information** |
| |
|
| | The FaceSwap API, built on a custom AI model, allows developers to effortlessly integrate advanced face-swapping capabilities to their platforms, offering users the ability to rapidly personalize images of their choice. |
| |
|
| |
|
| | ## Usage Steps |
| |
|
| | Below we share the code snippets on how to use the Faceswap API's endpoint. |
| | - The programming language is Python |
| | - Have 2 images (Each image must only contain one visible face) |
| |
|
| | **Create a task ID from the Faceswap endpoint** |
| |
|
| | <pre><code class="language-python"> |
| | <span class="hljs-keyword">import</span> http.client |
| | |
| | conn = http.client.HTTPSConnection(<span class="hljs-string">"api.piapi.ai"</span>) |
| | |
| | payload = <span class="hljs-string">"{\n \"target_image\": \"image1.png\",\n \"swap_image\": \"image2.png\",\n \"result_type\": \"url\"\n}"</span> |
| | |
| | headers = { |
| | <span class="hljs-built_in">'X-API-Key': "{{x-api-key}}"</span>, //Insert your API Key here |
| | <span class="hljs-built_in">'Content-Type': "application/json"</span>, |
| | <span class="hljs-built_in">'Accept': "application/json"</span> |
| | } |
| | |
| | conn.request("POST", "/api/face_swap/v1/async", payload, headers) |
| | |
| | res = conn.getresponse() |
| | data = res.read() |
| | |
| | <span class="hljs-keyword">print</span>(data.decode("utf-8")) |
| | </code></pre> |
| |
|
| |
|
| |
|
| | **Retrieve the task ID** |
| |
|
| | <pre><code class="language-python"> |
| | { |
| | <span class="hljs-built_in">"code"</span>: 200, |
| | <span class="hljs-built_in">"data"</span>: { |
| | <span class="hljs-built_in">"task_id"</span>: "7a7ba527************1974d4316e22" //Record the taskID provided in your response terminal |
| | }, |
| | <span class="hljs-built_in">"message"</span>: "success" |
| | } |
| | </code></pre> |
| | |
| |
|
| |
|
| | **Insert the Faceswap task ID into the fetch endpoint** |
| |
|
| | <pre><code class="language-python"> |
| | <span class="hljs-keyword">import</span> http.client |
| | |
| | conn = http.client.HTTPSConnection(<span class="hljs-string">"api.piapi.ai"</span>) |
| | |
| | payload = <span class="hljs-string">"{\n \"task_id\": \"7a7ba527************1974d4316e22\"\n}"</span> //Replace the task ID with your task ID |
| | |
| | headers = { |
| | <span class="hljs-built_in">'X-API-Key': "{{x-api-key}}"</span>, //Insert your API Key here |
| | <span class="hljs-built_in">'Content-Type': "application/json"</span>, |
| | <span class="hljs-built_in">'Accept': "application/json"</span> |
| | } |
| | |
| | conn.request("POST", "/api/face_swap/v1/fetch", payload, headers) |
| | |
| | res = conn.getresponse() |
| | data = res.read() |
| | |
| | <span class="hljs-keyword">print</span>(data.decode("utf-8")) |
| | </code></pre> |
| |
|
| |
|
| |
|
| | **For fetch endpoint responses** - Refer to our [documentation](https://piapi.ai/docs/faceswap-api/fetch) for more detailed information. |
| |
|
| |
|
| |
|
| | <br> |
| |
|
| |
|
| |
|
| | ## Contact us |
| |
|
| | Contact us at <a href="mailto:contact@piapi.ai">contact@piapi.ai</a> for any inquires. |
| |
|
| | <br> |
| |
|
| |
|
| |
|
| |
|
| |
|