Adding AI to your Next.js app has never been simpler! In this guide, we'll walk you through deploying and integrating powerful AI models, no Python required. With just a few clicks, you can access state-of-the-art (SOTA) algorithms from the Ikomia HUB and bring AI features into your JavaScript app hassle-free.
Here's what you'll learn:
Before getting started, make sure you have an Ikomia account. If you don’t have one yet, you can sign up using your email, Google, or GitHub account.
The Ikomia HUB provides access to over 100 AI algorithms, all deployable in just a few clicks. For this guide, we’ll be using the FLUX.1 diffusion model, a cutting-edge algorithm for image generation.
Simply navigate to the Ikomia HUB, search for FLUX.1, and select it for deployment.
Ikomia SCALE lets you deploy your workflows across various cloud providers and regions. You can choose from three main compute infrastructures:
For FLUX.1, we recommend at least 24GB of VRAM. In this example, we'll select the Nvidia L4 size M from Google Cloud for optimal performance.To deploy your selected workflow, follow these steps:
Click Add Deployment to launch your workflow.
Once added, your deployment will appear in the deployment list on the left side of the page. Setup time will vary based on the workflow and chosen configuration.
The SCALE platform offers an intuitive Test Interface to quickly verify your deployed workflow.
Open the Test Interface
Run Your Workflow
Note: The first run of FLUX.1 takes a few minutes as the system sets up the required models
This allows you to validate your deployment effortlessly before integrating it into your application.
Use your preferred package manager to install the client library:
To create a new Next.js project, run the following command:
During installation, you’ll be prompted with several configuration options. You can select the default settings or customize them based on your preferences:
Once the project is created, we get a sneak peek at the final tree structure we'll build by the end of the tutorial.
Before making API requests, you'll need to retrieve your deployment's endpoint and generate a secure token for authentication. Follow these steps to obtain the necessary credentials.
The endpoint is available on the left-hand side of the page under the deployments section.
1. Access Token Management: Navigate to the top right corner of the SCALE platform, then go to the settings or account section where you will find API token management.
2. Create New Token: Click on the option to create a new token. Fill in the required details such as the token's name and expiration date.
3. Generate and Save the Token.
4. Copy the Token: Once generated, copy the token. You are now ready to set the token as an environment variable.
Create a .env file in your project root directory and define the endpoint URL and authentication token. This file stores environment variables required to connect with the Ikomia SCALE API. The endpoint provides access to your deployed model, while the token ensures authenticated requests. Add the following variables to your .env file:
Implement a Route Handler to call your deployment and stream the results to the browser using the StreamingRun utility:
Since you are responsible for implementing your backend endpoint, you can easily incorporate your own logic to authenticate users, rate limit requests, add billing or any other custom constraints.
This React component allows users to input a prompt, sends it to the backend API (/api/generate-image), and displays the generated image. It dynamically updates the estimated time (ETA) and handles errors, ensuring a seamless user experience
Once everything is set up, it's time to run your Next.js app and test the AI-powered image generation with the FLUX.1 model. Follow these steps to get your application up and running:
Start the Development Server
Depending on the package manager you used for installation, run the appropriate command to start your Next.js application:
This will start your Next.js development server, usually at http://localhost:3000/
Access the Image Generation Interface
Et voilà! Your app is successfully generating images.
Adding AI to your Next.js app is now easier than ever with Ikomia HUB and SCALE. This guide walked you through deploying an AI model, setting up a backend endpoint, and creating a simple front-end to generate images, all without needing Python.
With just a few steps, you can integrate powerful AI models into your app while keeping things flexible. You get to choose your deployment setup and even customize the experience to fit your needs. Plus, since it’s all cloud-based, you don’t have to worry about heavy processing on your local machine!
Now that you’ve got everything up and running, you can start exploring more AI models, fine-tune performance, and add even more cool features to your app! 🚀