Skip to main content

Empower Your Apps with AI - Introducing Replicate Integration

Β· 5 min read
Deniz Colak

We are excited to announce the integration with Replicate. 🎊 Replicate is a service that lets us run pre-trained machine-learning models in the cloud. You can also use it to host our own public and private models. With this integration, developers can significantly speed up the development process and create more advanced AI apps. You can use different Replicate models such as stability-ai/stable-diffusion , tencentarc/gfpgan, yuval-alaluf/sam, openai/whisper and more to build amazing AI powered apps.

Amazing Use Cases with Replicate Integration​

With Replicate integration, the possibilities are endless. Here are some of the amazing use cases you can build with Replicate integration:

  • Image to Image Translation: You can use the stability-ai/stable-diffusion model to translate images from one domain to another. For example, you can translate a photo of a cat to a photo of a dog.

  • Image Restoration: You can use the tencentarc/gfpgan model to increase the resolution of an image. For example, you can increase the resolution of a low-resolution photo.

  • Age to Face Translation: You can use the yuval-alaluf/sam model to translate an age to a face. For example, you can translate a 30-year-old face to a 50-year-old face.

  • Convert Audio to Text: You can use the openai/whisper model to convert audio to text. For example, you can convert a voice recording to text.

  • Image from drawing: You can use the jagilley/controlnet-scribblemodel to convert a drawing to an image. For example, you can convert a drawing of a turtle to a photo of a turtle.

  • Midjourney like image generation: You can use the prompthero/openjourney model to generate images like Midjourney. For example, you can generate a photo of a person in a car.

  • More will be added soon...

On top of that, you can also use Stripe integration to accept payments from your users with subscription plans. Also, you can define credit limits for your users and charge them based on the usage of your app.

tip

Of course, you can use Replicate integration to build many more amazing apps. You can find more Replicate models here.

Building Your First AI Powered App with Replicate​

Getting API key from Replicate​

To use Replicate integration, you need to get an API key from Replicate. To do this, you can visit the Replicate website and click on the Sign Up button. After you sign up, you can visit the Account page and copy the API token.

Adding Replicate API token to Altogic​

Now open Altogic Designer and visit the Parameters view of the Settings to create a new application parameter for the API token as Replicate and select the type as Text.

Replicate Integration

Creating a new data model to store the response​

Before creating data model for the response, let's take a look the below diagram, here we will check the status field of the response to see if the prediction is completed or not. Then, if status is succeeded, we need to store the response in the database, otherwise, we can show the response to the user without storing it.

Business Flow
Flowchart of the business logic

Now, let's open Altogic Designer and create a new model. Click on the Add button and select Model from JSON. Copy and paste the following JSON to the editor and click on the Next button.

The response json will be as follows:

{
"id": "rrr4z55ocneqzikepnug6xezpe",
"version": "be04660a5b93ef2aff61e3668dedb4cbeb14941e62a3fd5998364a32d613e35e",
"urls": {
"get": "https://api.replicate.com/v1/predictions/rrr4z55ocneqzikepnug6xezpe",
"cancel": "https://api.replicate.com/v1/predictions/rrr4z55ocneqzikepnug6xezpe/cancel"
},
"created_at": "2022-09-13T22:54:18.578761Z",
"started_at": "2022-09-13T22:54:19.438525Z",
"completed_at": "2022-09-13T22:54:23.236610Z",
"source": "api",
"status": "succeeded",
"input": {
"prompt": "oak tree with boletus growing on its branches"
},
"output": null,
"error": null,
"logs": "Using seed: 36941...",
"metrics": {
"predict_time": 4.484541
}
}

After controlling the field types you can click Next and define model name as predictions and click Finish.

tip

You can also use the Replicate API documentation to get the response json.

  • In this example we will use the sczhou/codeformer model. It is robust Face Restoration algorithm for old photos. You can find the documentation here.

Watch the video below to see how to create a new model in Altogic with using Model from JSON option.

Creating a new endpoint and services for text generation​

After the model is created, you can create new endpoints and services to create a prediction and get a prediction. To do this, visit the Endpoints view of the Altogic Designer and follow the steps as shown in the video below.



In the video, you can see the steps for creating a new endpoint and service in Altogic, as well as how to utilize the Replicate nodes to create a prediction, get a prediction, and save the response to a database. It also shows how to test the endpoint using the Altogic Tester and view generated images in the Altogic Navigator.

info
  • If you want to build more complex apps with different features, like credit limits, subscription plans, and more, you can use the Stripe integration to accept payments from your users. You can find the SaaS starter application from here.

Conclusion​

In this article, we took a look at how to use Replicate integration to build AI powered apps in minutes. We also learn some of the amazing use cases you can build with it. We hope you enjoyed this article. If you have any questions, please feel free to reach out to us at community forumΒ orΒ discord channel.