You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NV-CLIP is a multimodal embeddings model for image and text and this is a sample application that shows how to use the OpenAI SDK with NVIDIA Inference Microservice (NIM). Whether you are using a NIM from [build.nvidia.com/](https://build.nvidia.com/) or a self-hosted NIM, this sample application will work for both.
3
+
NV-CLIP is a multimodal embeddings model for image and text, and this is a sample application that shows how to use the OpenAI SDK with NVIDIA Inference Microservice (NIM). Whether you are using a NIM from [build.nvidia.com/](https://build.nvidia.com/) or [a self-hosted NIM](https://docs.nvidia.com/nim/nvclip/latest/getting-started.html#option-2-from-ngc), this sample application will work for both.
4
4
5
-
###Quick Start
5
+
## Quick Start
6
6
7
-
1. Add API key in `nvidia_nim.yaml`
7
+
Get your [API Key](https://docs.nvidia.com/nim/nvclip/latest/getting-started.html#generate-an-api-key) and start the sample application.
Use the `nvidia_nim.yaml` configuration file to configure the sample application:
13
17
14
-
### Connection Information
18
+
### NVIDIA-Hosted NV-CLIP NIM
19
+
20
+
By default, the application is configured to use NVIDIA-hosted NV-CLIP NIM.
15
21
16
22
```
17
23
nim:
18
-
base_url: https://integrate.api.nvidia.com/v1
19
-
api_key:
24
+
base_url: https://integrate.api.nvidia.com/v1
25
+
api_key:
20
26
21
27
```
22
28
23
-
`base_url`: The URL of your NIM instance. Defaults to NVIDIAhosted NIMs.
24
-
`api_key`: Your API key to access NVIDIAhosted NIMs.
29
+
`base_url`: The URL of your NIM instance. Defaults to NVIDIA-hosted NIMs.
30
+
`api_key`: Your API key to access NVIDIA-hosted NIMs.
25
31
26
-
## Run the sample application
27
32
28
-
There are a couple of options to run the sample application:
33
+
Note: you may also configure your API key using an environment variable.
34
+
E.g., `export API_KEY=...`
35
+
36
+
```bash
37
+
# To use NVIDIA hosted NIMs available on build.nvidia.com, export your API key first
38
+
export API_KEY=[enter your API key here]
39
+
```
40
+
29
41
30
-
### Run using Docker
42
+
### Self-Hosted NIMs
31
43
32
-
To run the sample application with Docker, you must first build a Docker image that includes the sample application and its dependencies:
44
+
To use a self-hosted NIM, refer to the [NV-CLIP](https://docs.nvidia.com/nim/nvclip/latest/getting-started.html) NIM documentation to configure and start the NIM.
45
+
46
+
Then, comment out the NVIDIA-hosted section and uncomment the self-hosted configuration section in the `nvidia_nim.yaml` file.
47
+
48
+
```bash
49
+
nim:
50
+
base_url: http://0.0.0.0:8000/v1/
51
+
encoding_format: float
52
+
api_key: NA
53
+
model: nvidia/nvclip-vit-h-14
54
+
```
55
+
56
+
57
+
### Build The Application
58
+
59
+
To run the sample application, you must first build a Docker image that includes the sample application and its dependencies:
33
60
34
61
```
35
62
# Build the Docker images from the root directory of Holohub
@@ -39,35 +66,49 @@ To run the sample application with Docker, you must first build a Docker image t
39
66
Then, run the Docker image:
40
67
41
68
```bash
42
-
./dev_container launch
69
+
./dev_container launch
43
70
```
44
71
45
72
46
-
### Start the Application
73
+
### Run the Application
47
74
48
75
To use the NIMs on [build.nvidia.com/](https://build.nvidia.com/), configure your API key in the `nvidia_nim.yaml` configuration file and run the sample app as follows:
49
76
50
-
note: you may also configure your api key using an environment variable.
51
-
E.g., `export API_KEY=...`
52
-
53
77
```bash
54
-
# To use NVIDIA hosted NIMs available on build.nvidia.com, export your API key first
55
-
export API_KEY=[enter your api key here]
56
-
57
78
./run launch nvidia_nim_nvclip
58
79
```
59
80
60
-
Have fun!
81
+
## Using the Application
82
+
83
+
Once the application is ready, it will prompt you to input URLs to the images you want to perform inference.
84
+
85
+
```bash
86
+
Enter a URL to an image: https://domain.to/my/image-cat.jpg
87
+
Downloading image...
88
+
89
+
Enter a URL to another image or hit ENTER to continue: https://domain.to/my/image-rabbit.jpg
90
+
Downloading image...
91
+
92
+
Enter a URL to another image or hit ENTER to continue: https://domain.to/my/image-dog.jpg
93
+
Downloading image...
94
+
95
+
```
61
96
97
+
If there are no more images that you want to use, hit ENTER to continue and then enter a prompt:
62
98
63
-
## Connecting with Locally Hosted NIMs
99
+
```bash
100
+
Enter a URL to another image or hit ENTER to continue:
64
101
65
-
To use a locally hosted NIM, first download and start the NIM.
66
-
Then configure the `base_url` parameter in the `nvidia_nim.yaml` configuration file to point to your local NIM instance.
102
+
Enter a prompt: Which image contains a rabbit?
103
+
```
67
104
68
-
The following example shows a NIM running locally and serving its APIs and the `meta-llama3-8b-instruct` model from `http://0.0.0.0:8000/v1`.
105
+
The application will connect to the NIM to generate an answer and then calculate the cosine similarity between the images and the prompt:
0 commit comments