Creating Your AI Apps
Learn how to interact with apps using Clarifai SDKs
Unlock the power of artificial intelligence by seamlessly integrating Clarifai SDKs into your application development process. With the Clarifai SDKs, creating intelligent and visually aware applications has never been more accessible.
Empower your apps with cutting-edge AI capabilities, from image and video recognition to natural language processing. Our SDKs provides a user-friendly interface, allowing developers to harness the full potential of Clarifai's state-of-the-art models effortlessly.
Create App
Leverage the Clarifai SDKs to seamlessly generate a new application, complete with a distinct and unique app ID. The API empowers you to effortlessly create apps tailored to your specific requirements, unlocking the potential for innovative and personalized experiences.
Visit this page for more information.
If you create an application via the API, Universal will be set as default base workflow unless you specify a different one.
- Python
- Typescript
from clarifai.client.user import User
client = User(user_id="user_id", pat="YOUR_PAT")
# You can create an app by providing the app id
app = client.create_app(app_id="test_app", base_workflow="Empty")
Output
2024-01-15 16:11:26 INFO clarifai.client.user: user.py:122
App created
code: SUCCESS
description: "Ok"
req_id: "1728082daee63fa593411dcb573e7e33"
import { User } from "clarifai-nodejs";
const client = new User({
userId: process.env.CLARIFAI_USER_ID,
pat: process.env.CLARIFAI_PAT,
appId: "",
});
// You can create an app by providing the app id
const app = await client.createApp({
appId: "test_app",
});
console.log(app);
Create App With Different Base Workflow
The API empowers you to establish an app with distinct base workflows, offering flexibility and adaptability.
Choose from a range of available base workflows, including Empty, Universal, Language Understanding, and General. This enables you to seamlessly integrate and customize the fundamental structure of your app, ensuring it aligns perfectly with your project requirements.
Visit this page for more information.
- Python
from clarifai.client.user import User
client = User(user_id="user_id", pat="YOUR_PAT")
# You can set the base workflow as ["Empty","Universal","Language-Understanding","General"]
app = client.create_app(app_id="test_app_2", base_workflow="Universal")
Output
2024-01-15 16:19:23 INFO clarifai.client.user: user.py:122
App created
code: SUCCESS
description: "Ok"
req_id: "7e7e9eaaebbd3c8f7ba6bf5e5cc7f2a3"
Patch App
You can perform patch operations on an app by merging, removing, or overwriting data. By default, all actions support overwriting, with specific behaviors for lists of objects.
- The
merge
action updates an existingkey:value
pair withkey:new_value
or appends to an existing list. For dictionaries, it merges objects that share a matchingid
field. - The
remove
action is only used to delete the app's cover image on the platform UI. - The
overwrite
action fully replaces an existing object with a new one.
Below is an example of performing patch operations on an app, where the base workflow is updated, the app is switched to an app template, and changes are made to the app's description, notes, default language, and image URL.
- Python
from clarifai.client.user import User
# Initialize the Clarifai client with the specified user ID
client = User(user_id='YOUR_USER_ID_HERE', pat='YOUR_PAT')
# Update the app by overwriting the base workflow with a new one, e.g., 'Empty'
client.patch_app(app_id='YOUR_APP_ID_HERE', action='overwrite', base_workflow='Empty')
# Update the app to make it an app template
client.patch_app(app_id='YOUR_APP_ID_HERE', action='overwrite', is_template=True)
# Overwrite the app's description, notes, and default language
client.patch_app(app_id='YOUR_APP_ID_HERE', action='overwrite', default_language='fr', description='Demo testing', notes="Hi Guys! This note is for Demo")
# Overwrite the app's image URL with a new one
client.patch_app(app_id='YOUR_APP_ID_HERE', action='overwrite', image_url='https://samples.clarifai.com/metro-north.jpg')
# Remove the app's image by specifying the 'remove' action
client.patch_app(app_id='YOUR_APP_ID_HERE', image_url='https://samples.clarifai.com/metro-north.jpg', action='remove')
Listing Apps
The Clarifai SDKs provides a convenient API to retrieve a list of all the apps available in your account. The list_apps function is a powerful tool that not only fetches the information but also supports essential features such as pagination for optimal data display.The use of parameters like page_no
and per_page
empowers you to customize the retrieval process based on your specific requirements.
Visit this page for more information.
- Python
- Typescript
from clarifai.client.user import User
# the list_apps method allows pagination
apps = list(User("user_id", pat="YOUR_PAT").list_apps(page_no=1,per_page=6))
for app in apps:
print("App id: ", app.id)
Output
App id: test_app_3
App id: test_app_2
App id: test_app
App id: APP_ID
App id: demo_app
App id: test
import { User } from "clarifai-nodejs";
const client = new User({
userId: process.env.CLARIFAI_USER_ID,
pat: process.env.CLARIFAI_PAT,
appId: "",
});
// list apps method allows pagination
const apps = await client
.listApps({
pageNo: 1,
perPage: 6,
})
.next();
if (apps.value)
for (const app of apps.value) {
console.log(app);
}
Delete App
In the Clarifai SDKs, the "Delete App" functionality empowers users to seamlessly remove an app from their account by specifying the unique App ID. This API-driven approach simplifies the app management process, allowing for efficient deletion of redundant or unused applications.
Be certain that you want to delete a particular app as the operation cannot be undone.
- Python
- Typescript
from clarifai.client.user import User
# Provide the app id as parameter to delete_app function
user = User("user_id", pat="YOUR_PAT").delete_app("test_app_2")
Output
2024-01-15 16:28:09 INFO clarifai.client.user: user.py:230
App Deleted
code: SUCCESS
description: "Ok"
details: "application \'test_app_2\' deleted"
req_id: "35bec06c2b871f335064ec2f197344b1"
import { User } from "clarifai-nodejs";
const client = new User({
userId: process.env.CLARIFAI_USER_ID,
pat: process.env.CLARIFAI_PAT,
appId: "",
});
// Provide the app id as parameter to delete_app function
await client.deleteApp({
appId: "test_app",
});
Create Concept
With the Clarifai SDKs, you have the capability to effortlessly create concepts by uploading input data to your app, accompanied by a specified label. This process automates the creation of concepts, streamlining the integration of new ideas or entities into your application.
Visit this page for more information.
- Python
- Typescript
from clarifai.client.input import Inputs
image_url = "https://2.img-dpreview.com/files/p/E~C1000x0S4000x4000T1200x1200~articles/3925134721/0266554465.jpeg"
# You can set the label parameter inorder to create a concept while uploading inputs
input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")
input_obj.upload_from_url(
input_id="demo2",
image_url=image_url,
labels=["train"],
)
Output
2024-01-15 16:53:00 INFO clarifai.client.input: input.py:669
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "d54e6e6ef983e32cadbc7e6134a829a2"
import { Input } from "clarifai-nodejs";
const imageUrl =
"https://2.img-dpreview.com/files/p/E~C1000x0S4000x4000T1200x1200~articles/3925134721/0266554465.jpeg";
const input = new Input({
authConfig: {
userId: process.env.CLARIFAI_USER_ID,
pat: process.env.CLARIFAI_PAT,
appId: "test_app",
},
});
await input.uploadFromUrl({
imageUrl,
inputId: "demo2",
labels: ["train"],
});
List Concept
The List Concepts feature in the Clarifai SDKs empowers users to retrieve a comprehensive list of all available concepts within their application. With the list_concepts function, users can seamlessly navigate through large sets of concepts by leveraging built-in pagination functionalities. This enables efficient information display while providing flexibility through parameters such as page_no
and items per_page
.
Visit this page for more information.
- Python
- Typescript
from clarifai.client.app import App
app = App(app_id="test_app", user_id="user_id", pat="YOUR_PAT")
# the list_concepts method allows pagination
all_concepts = list(app.list_concepts(page_no=1,per_page=1))
Output
[id: "id-train"
name: "train"
value: 1
created_at {
seconds: 1705317780
nanos: 434442000
}
language: "en"
app_id: "test_app"
visibility {
gettable: PRIVATE
}
]
import { App } from "clarifai-nodejs";
const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: "test_app",
},
});
const list = await app
.listConcepts({
pageNo: 1,
perPage: 6,
})
.next();
const concepts = list.value;
console.log(concepts);