درک تصویر

مدل‌های Gemini از ابتدا به گونه‌ای ساخته شده‌اند که چندوجهی باشند و طیف گسترده‌ای از وظایف پردازش تصویر و بینایی کامپیوتر، از جمله (اما نه محدود به) شرح تصویر، طبقه‌بندی و پاسخ به سؤالات بصری را بدون نیاز به آموزش مدل‌های تخصصی یادگیری ماشین، امکان‌پذیر سازند.

مدل‌های Gemini علاوه بر قابلیت‌های چندوجهی عمومی خود، از طریق آموزش‌های اضافی، دقت بیشتری را برای موارد استفاده خاص مانند تشخیص و قطعه‌بندی اشیاء ارائه می‌دهند.

ارسال تصاویر به جمینی

شما می‌توانید با استفاده از چندین روش، تصاویر را به عنوان ورودی به Gemini ارائه دهید:

ارسال تصویر با استفاده از URL

شما می‌توانید با استفاده از Files API یک تصویر آپلود کنید و آن را در درخواست ارسال کنید:

پایتون

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="path/to/organ.jpg")

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input=[
        {"type": "text", "text": "Caption this image."},
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        }
    ]
)
print(interaction.output_text)

جاوا اسکریپت

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.7-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.7-flash",
    "input": [
      {"type": "text", "text": "Caption this image."},
      {
        "type": "image",
        "uri": "YOUR_FILE_URI",
        "mime_type": "image/jpeg"
      }
    ]
  }'

ارسال داده‌های تصویر درون‌خطی

شما می‌توانید داده‌های تصویر را به صورت رشته‌های کدگذاری شده با base64 ارائه دهید:

پایتون

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.7-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)

جاوا اسکریپت

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.7-flash",
    input: [
        {type: "text",