تم تصميم نماذج Gemini لتكون متعدّدة الوسائط منذ البداية، ما يتيح مجموعة واسعة من مهام معالجة الصور والرؤية الحاسوبية، بما في ذلك على سبيل المثال لا الحصر، وضع تعليقات توضيحية للصور وتصنيفها والإجابة عن الأسئلة المرئية بدون الحاجة إلى تدريب نماذج تعلُّم آلي متخصّصة.
بالإضافة إلى إمكاناتها العامة المتعدّدة الوسائط، توفّر نماذج Gemini دقة محسّنة لحالات استخدام معيّنة، مثل رصد الأجسام وتقسيمها، من خلال تدريب إضافي.
إرسال الصور إلى Gemini
يمكنك تقديم الصور كمدخلات إلى Gemini باستخدام عدة طرق:
- إرسال صورة باستخدام عنوان URL: هذه الطريقة مثالية للصور المتاحة للجميع.
- إرسال بيانات صورة مضمّنة: هذه الطريقة مناسبة لبيانات الصور المرمّزة باستخدام base64.
- تحميل الصور باستخدام File API: ننصح بهذه الطريقة لـ الملفات الأكبر حجمًا أو لإعادة استخدام الصور في طلبات متعدّدة.
إرسال صورة باستخدام عنوان URL
يمكنك تحميل صورة باستخدام 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);
راحة
# 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);
راحة
IMG_PATH="/path/to/your/image1.jpg"
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"