Face swap and animate images generated by Midjourney using InsightFaceSwap and Pika
Tags: midjourney, insightfaceswap, pika, api
Published: 2024-02-26 02:50:16

### Introduction

This article covers multiple experimental APIs provided by [useapi.net](https://useapi.net).

You will learn how you can easily generate and upscale images from your prompt(s) using Midjourney, apply face swap via InsightFaceSwap, and finally animate the result using Pika.

First, we will be generating images using the [/imagine](https://docs.midjourney.com/docs/quick-start#5-use-the-imagine-command) command from [Midjourney](https://midjourney.com) and upscaling them with the [/button](https://useapi.net/docs/api-v2/post-jobs-button) command using the experimental [Midjorney API](https://useapi.net/docs/api-v2).

Next, we will use the [InsightFaceSwap Discord Bot](https://discord.gg/Ym3X8U59ZN) by [Picsi.Ai](https://www.picsi.ai/) using the experimental [InsightFaceSwap API](https://useapi.net/docs/api-faceswap-v1) to swap faces on the upscaled images mentioned above.

Finally, animation provided by the [Pika Discord Bot](https://discord.gg/pika) will be applied to the face swapped images via the experimental [Pika API](https://useapi.net/docs/api-pika-v1).

Please check out the 👉 [YouTube video](https://www.youtube.com/watch?v=fTBi4-cG5DY) 👈 showcasing the final results of these generations from this article.

This article explains how to use a `webhook` to retrieve generated results and how to structure a basic query to submit requests to the API. This approach is much more performant and consumes fewer resources.

### Setup 

We will use the experimental API provided by [useapi.net](https://useapi.net) to interact with Midjourney, InsightFaceSwap and Pika Discord bots.

#### Useapi.net

You need a monthly [subscription](https://useapi.net/docs/subscription) to use the [useapi.net](https://useapi.net) experimental APIs mentioned in this article.
Follow these [steps](https://useapi.net/docs/start-here/setup-useapi) to get started.

#### Midjourney

Naturally you'll need a Discord account with an active [Midjourney subscription](https://docs.midjourney.com/docs/plans#plan-comparison). The $10 Basic Plan will suffice.

Follow these [simple steps](https://useapi.net/docs/start-here) to obtain the following:

- Discord server ID number, referred to in this article as `server`.
- Discord channel ID number, referred to in this article as `channel`.
- Discord token, referred to in this article as `discord`. [Verify Discord access](https://useapi.net/docs/start-here/setup-midjourney#verify-discord-access).
- Once you have all the above, please create or update your [Midjourney account information](https://useapi.net/docs/api-v2/post-account-midjourney-channel) so that you no longer need to provide them with every API call. 

#### InsightFaceSwap

The InsightFaceSwap setup is similar to Midjourney's, please follow [our instructions](https://useapi.net/docs/start-here/setup-faceswap). 

InsightFaceSwap allows users to swap faces from source images onto different target images. It offers free and paid [subscriptions](https://www.patreon.com/picsi). Paid subscribers have access to a wide selection of extra features, such as [HiFidelity Mode](https://www.patreon.com/posts/89036144), [ARTIFY](https://www.patreon.com/posts/picsi-ai-v2-0-97389077), oldify/youngify, morphing multiple faces in one image, and [many more](https://discord.com/channels/1095014106576212101/1128550062683865178). 

You can add the InsightFaceSwap Discord bot to the same server and channel as the Midjourney bot to speed up and simplify the setup process. If you're planning to use the free plan, you may want to consider setting up multiple Discord/InsightFaceSwap accounts so that you can execute more operations daily, since one account alone may not suffice.

#### Pika

The Pika Discord bot is currently free. The setup process is very similar to the ones above. Please refer to the [Pika setup steps](https://useapi.net/docs/start-here/setup-pika). Since you have already retrieved your Discord token during the Midjourney setup, you only need to identify the channel for Pika Direct Messages.

Useapi.net provides an easy way to experiment with all API endpoints without writing any code. Check the `Try It` section at the end of each document page, such as Midjourney's [jobs/imagine](https://useapi.net/docs/api-v2/post-jobs-imagine#try-it), InsightFaceSwap's [faceswap/swap](https://useapi.net/docs/api-faceswap-v1/post-faceswap-swap#try-it), or Pika's [pika/animate](https://useapi.net/docs/api-pika-v1/post-pika-animate#try-it).

For your convenience, we have published all the [source code](https://github.com/useapi/examples/tree/main/imagine-faceswap-animate) used in this article. You can choose between JavaScript and Python examples. Clone this repository locally and use it as a starting point for your experiments.

#### Ngrok 

Follow official [instructions](https://ngrok.com/docs/getting-started/#step-2-connect-your-account) to sign up for an ngrok account and copy your ngrok `authtoken` from your ngrok dashboard.

### Preparing Midjourney Prompts

Let's use [ChatGPT](https://chat.openai.com) to create a list of prompts. Here's our ChatGPT prompt:

> Create a simple JSON array of strings containing Midjourney prompts to generate the world's most renowned portrait paintings.

The output will look something like this:

```json
[
  "Portrait of a Young Man by Raphael",
  "Salvator Mundi by Leonardo da Vinci",
  …
  "Mona Lisa (La Gioconda) by Leonardo da Vinci"
]
```

An array of prompts generated by ChatGPT needs to be saved to a locally cloned [prompts.json](https://github.com/useapi/examples/blob/main/imagine-faceswap-animate/prompts.json) file.

### Executing Prompts Using the Midjourney, InsightFaceSwap and Pika experimental API by useapi.net

Create a file locally in the same folder named `example.sh` with the following content:

#### [JavaScript](https://github.com/useapi/examples/blob/main/imagine-faceswap-animate/example.js)
```bash
USEAPI_TOKEN="useapi API token" NGROK_AUTHTOKEN="ngrok authtoken" node ./example.js
```

#### [Python](https://github.com/useapi/examples/blob/main/imagine-faceswap-animate/example.py)
```bash
USEAPI_TOKEN="useapi API token" NGROK_AUTHTOKEN="ngrok authtoken" python3 ./example.py
```

### Examples
* [Upscaled image](https://useapi.net/assets/images/articles/imagine-faceswap-animate-upscaled.png) generated by Midjourney.  
* [Face swapped image](https://useapi.net/assets/images/articles/imagine-faceswap-animate-faceswap.png) generated by InsightFaceSwap from upscaled image above.  
* [Video](https://useapi.net/assets/images/articles/imagine-faceswap-animate-animated.mp4) generated from face swapped image above using `text + image` animation by Pika.  

We used [Rick Astley](https://github.com/useapi/examples/blob/main/imagine-faceswap-animate/source.jpg) as a source image for face swapping, feel free to change it per your liking.

### Conclusion

Visit our [Discord Server](https://discord.gg/w28uK3cnmF) or [Telegram Channel](https://t.me/use_api) for any support questions and concerns. 

We regularly post guides and tutorials on the [YouTube Channel](https://www.youtube.com/@midjourneyapi).

Execute it from the command line like this: `./example.sh` and observe the magic of the experimental API. 

The generated images and videos will be saved locally. You may proceed with the generation process within a Discord channel to further refine your creations. Alternatively, you can continue automate the process by using the [jobs/button](https://useapi.net/docs/api-v2/post-jobs-button) along with [Pika](https://useapi.net/docs/api-pika-v1) or perhaps [InsightFaceSwap](https://useapi.net/docs/api-faceswap-v1), following the same process as demonstrated above.

### Examples
[Upscaled image](https://useapi.net/assets/images/articles/imagine-faceswap-animate-upscaled.png) generated by Midjourney.  
[Face swapped image](https://useapi.net/assets/images/articles/imagine-faceswap-animate-faceswap.png) generated by InsightFaceSwap from upscaled image above.  
[Video](https://useapi.net/assets/images/articles/imagine-faceswap-animate-animated.mp4) generated from face swapped image above using `text + image` animation by Pika.  

We used [Rick Astley](https://github.com/useapi/examples/blob/main/imagine-faceswap-animate/source.jpg) as a source image for face swapping, feel free to change it per your liking.

### Conclusion

Visit our [Discord Server](https://discord.gg/w28uK3cnmF) or [Telegram Channel](https://t.me/use_api) for any support questions and concerns. 

We regularly post guides and tutorials on the [YouTube Channel](https://www.youtube.com/@midjourneyapi).