Gemini मॉडल, मल्टीमोडल के तौर पर काम करने के लिए डिज़ाइन किए गए हैं. इसलिए, इमेज प्रोसेसिंग और कंप्यूटर विज़न से जुड़े कई टास्क के लिए इनका इस्तेमाल किया जा सकता है. इनमें इमेज कैप्शनिंग, क्लासिफ़िकेशन, और विज़ुअल सवालों के जवाब देने जैसे टास्क शामिल हैं. इसके लिए, एमएल के खास मॉडल को ट्रेनिंग देने की ज़रूरत नहीं होती.
Gemini मॉडल, सामान्य मल्टीमोडल क्षमताओं के अलावा, खास इस्तेमाल के मामलों में ज़्यादा सटीक नतीजे देते हैं. जैसे, ऑब्जेक्ट का पता लगाना और सेगमेंटेशन. इसके लिए, उन्हें अतिरिक्त ट्रेनिंग दी जाती है.
Gemini को इमेज पास करना
Gemini को इनपुट के तौर पर इमेज देने के लिए, इन तरीकों का इस्तेमाल किया जा सकता है:
- यूआरएल का इस्तेमाल करके इमेज पास करना: यह सार्वजनिक तौर पर ऐक्सेस की जा सकने वाली इमेज के लिए सबसे सही है.
- इनलाइन इमेज डेटा पास करना: यह base64-एन्कोड किए गए इमेज डेटा के लिए है.
- File API का इस्तेमाल करके इमेज अपलोड करना: यह बड़ी फ़ाइलों के लिए या एक से ज़्यादा अनुरोधों में इमेज का फिर से इस्तेमाल करने के लिए सबसे सही है.
यूआरएल का इस्तेमाल करके इमेज पास करना
Files API का इस्तेमाल करके इमेज अपलोड की जा सकती है और इसे अनुरोध में पास किया जा सकता है:
Python
from google import genai
client = genai.Client()
uploaded_file = client.files.upload(file="path/to/organ.jpg")
interaction = client.interactions.create(
model="gemini-3.6-flash",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const uploadedFile = await client.files.upload({
file: "path/to/organ.jpg",
config: { mimeType: "image/jpeg" }
});
const interaction = await client.interactions.create({
model: "gemini-3.6-flash",
input: [
{type: "text", text: "Caption this image."},
{
type: "image",
uri: uploadedFile.uri,
mime_type: uploadedFile.mimeType
}
]
});
console.log(interaction.output_text);
REST
# First upload the file using the Files API, then use the URI:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.6-flash",
"input": [
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}'
इनलाइन इमेज डेटा पास करना
base64-एन्कोड की गई स्ट्रिंग के तौर पर इमेज डेटा दिया जा सकता है:
Python
import base64
from google import genai
with open('path/to/small-sample.jpg', 'rb') as f:
image_bytes = f.read()
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.6-flash",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"data": base64.b64encode(image_bytes).decode('utf-8'),
"mime_type": "image/jpeg"
}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const client = new GoogleGenAI({});
const base64ImageFile = fs.readFileSync("path/to/small-sample.jpg", {
encoding: "base64",
});
const interaction = await client.interactions.create({
model: "gemini-3.6-flash",
input: [
{type: "text", text: "Caption this image."},
{
type: "image",
data: base64ImageFile,
mime_type: "image/jpeg"
}
]
});
console.log(interaction.output_text);
REST
IMG_PATH="/path/to/your/image1.jpg"
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"
else
B64FLAGS="-w0"
fi
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.6-flash",
"input": [
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"data": "'"$(base64 $B64FLAGS $IMG_PATH)"'",
"mime_type": "image/jpeg"
}
]
}'
File API का इस्तेमाल करके इमेज अपलोड करना
बड़ी फ़ाइलों के लिए या एक ही इमेज फ़ाइल को बार-बार इस्तेमाल करने के लिए, Files API का इस्तेमाल करें. Files API की गाइड देखें.
Python
from google import genai
client = genai.Client()
my_file = client.files.upload(file="path/to/sample.jpg")
interaction = client.interactions.create(
model="gemini-3.6-flash",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": my_file.