Imagen के सभी मॉडल बंद किए जा रहे हैं. इन्हें 24 जून, 2026 को बंद कर दिया जाएगा. इन्हें बंद करने का फ़ैसला, Google के सभी प्रॉडक्ट और Gemini Developer API और Vertex AI Gemini API, दोनों पर लागू होता है.
सेवा में रुकावट से बचने के लिए, आपको अपने ऐप्लिकेशन को Imagen मॉडल से Gemini इमेज मॉडल (जिन्हें "Nano Banana" मॉडल भी कहा जाता है) पर माइग्रेट करना होगा. इसके लिए, इस गाइड में बताया गया तरीका अपनाएं. यह काम, 24 जून, 2026 से पहले कर लें.
अगर आपको इसे बंद करने से जुड़ी कोई ज़रूरी समस्या है, तो Firebase की सहायता टीम से संपर्क करें.
रिप्लेसमेंट Gemini इमेज मॉडल
अपने ऐप्लिकेशन के लिए, इमेज मॉडल चुनने के लिए, यहां दी गई टेबल देखें.Gemini
| Imagen मॉडल | Gemini इमेज मॉडल ("Nano Banana") |
|---|---|
imagen-4.0-fast-generate-001 |
gemini-2.5-flash-image (GA)gemini-3.1-flash-image-preview (with thinking level
MINIMAL) |
imagen-4.0-generate-001 |
gemini-2.5-flash-image (GA)gemini-3.1-flash-image-preview (with thinking level
HIGH) |
imagen-4.0-ultra-generate-001 |
gemini-2.5-flash-image (GA)gemini-3-pro-image-preview |
imagen-3.0-capability-001 |
gemini-2.5-flash-image (GA)gemini-3.1-flash-image-preview |
अपने ऐप्लिकेशन को माइग्रेट करना
इस सेक्शन में, Imagen मॉडल से Gemini इमेज मॉडल पर माइग्रेट करने के पहले और बाद के उदाहरण दिखाए गए हैं.
टेक्स्ट की मदद से इमेज जनरेट करना
|
इस पेज पर, अपने Gemini API प्रोवाइडर के हिसाब से कॉन्टेंट और कोड देखने के लिए, उस पर क्लिक करें. |
टेक्स्ट की मदद से इमेज जनरेट करने के लिए, अपने ऐप्लिकेशन को माइग्रेट करें:
किसी ऐसे इमेज मॉडल का इस्तेमाल करें जो Geminiकी जगह काम कर सके . जैसे,
gemini-2.5-flash-image.ImagenModelइंस्टेंस के बजाय,GenerativeModelइंस्टेंस बनाएं.इमेज मॉडल के हिसाब से, मॉडल कॉन्फ़िगरेशन के विकल्प अपडेट करें Gemini.
- इस कॉन्फ़िगरेशन के तहत, रिस्पॉन्स मोडैलिटी को
IMAGEपर सेट करें.
ध्यान दें कि Gemini इमेज मॉडल को इस तरह कॉन्फ़िगर किया जा सकता है कि वे इमेज और टेक्स्ट, दोनों को लौटा सकें.
- इस कॉन्फ़िगरेशन के तहत, रिस्पॉन्स मोडैलिटी को
(Vertex AI Gemini API सिर्फ़) मॉडल को ऐक्सेस करने की जगह को, Gemini इमेज मॉडल के लिए काम करने वाली किसी जगह पर अपडेट करें. हमारा सुझाव है कि
globalका इस्तेमाल करें.
Swift
पहले
import FirebaseAILogic
// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create an `ImagenModel` instance with a model that supports your use case
let model = ai.imagenModel(modelName: "IMAGEN_MODEL_NAME")
// Provide an image generation prompt
let prompt = "An astronaut riding a horse"
// To generate an image, call `generateImages` with the text prompt
let response = try await model.generateImages(prompt: prompt)
// Handle the generated image
guard let image = response.images.first else {
fatalError("No image in the response.")
}
let uiImage = UIImage(data: image.data)
बाद में
import FirebaseAILogic
// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a Gemini model that supports image output
let model = ai.generativeModel(
modelName: "GEMINI_IMAGE_MODEL_NAME",
generationConfig: GenerationConfig(
responseModalities: [.image],
imageConfig: ImageConfig(aspectRatio: .landscape4x3)
)
)
// Provide an image generation prompt
let prompt = "An astronaut riding a horse"
// To generate an image, call `generateContent` with the text prompt
let response = try await model.generateContent(prompt)
// Handle the case where no images were generated
guard let inlineDataPart = response.inlineDataParts.first else {
fatalError("No image in the response.")
}
// Process the image
guard let uiImage = UIImage(data: inlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
Kotlin
पहले
// Initialize the Gemini Developer API backend service
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())
// Create an `ImagenModel` instance with an Imagen model that supports your use case
val model = ai.imagenModel("IMAGEN_MODEL_NAME")
// Provide an image generation prompt
val prompt = "An astronaut riding a horse"
// To generate an image, call `generateImages` with the text prompt
val imageResponse = model.generateImages(prompt)
// Handle the generated image
val image = imageResponse.images.first()
val bitmapImage = image.asBitmap()
बाद में
// Initialize the Gemini Developer API backend service
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())
// Create a `GenerativeModel` instance with a Gemini model that supports image output
val model = ai.generativeModel(
modelName = "GEMINI_IMAGE_MODEL_NAME",
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.IMAGE),
imageConfig = imageConfig {
aspectRatio = AspectRatio.LANDSCAPE_4x3
}
}
)
// Provide an image generation prompt
val prompt = "An astronaut riding a horse"
// To generate an image, call `generateContent` with the text prompt
val imageResponse = model.generateContent(prompt)
if (imageResponse.finishReason == FinishReason.NO_IMAGE) {
// Handle the case where no images were generated
} else {
// Handle the generated image
val bitmapImage = imageResponse.candidates.first().content.parts.filterIsInstance().firstOrNull()?.image
}
Java
पहले
// Initialize the Gemini Developer API backend service
// Create an `ImagenModel` instance with an Imagen model that supports your use case
ImagenModel imagenModel = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
/* modelName */ "IMAGEN_MODEL_NAME");
ImagenModelFutures model = ImagenModelFutures.from(imagenModel);
// Provide an image generation prompt
String prompt = "An astronaut riding a horse";
// To generate an image, call `generateImages` with the text prompt
Futures.addCallback(model.generateImages(prompt), new FutureCallback<ImagenGenerationResponse>() {
@Override
public void onSuccess(ImagenGenerationResponse result) {
if (result.getImages().isEmpty()) {
Log.d("TAG", "No images generated");
}
Bitmap bitmap = result.getImages().get(0).asBitmap();
// Use the bitmap to display the image in your UI
}
@Override
public void onFailure(Throwable t) {
// ...
}
}, Executors.newSingleThreadExecutor());
बाद में
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a Gemini model that supports image output
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"GEMINI_IMAGE_MODEL_NAME",
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.IMAGE))
.setImageConfig(new ImageConfig(AspectRatio.LANDSCAPE_4x3, null))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt instructing the model to generate an image
Content prompt = new Content.Builder()
.addText("An astronaut riding a horse")
.build();
// To generate an image, call `generateContent` with the text input
Executor executor = Executors.newSingleThreadExecutor();
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse result) {
if (result.finishReason == FinishReason.NO_IMAGE) {
// handle the case where no images were generated
return;
}
// iterate over all the parts in the first candidate in the result object
for (Part part : result.getCandidates().get(0).getContent().getParts()) {
if (part instanceof ImagePart) {
ImagePart imagePart = (ImagePart) part;
// The returned image as a bitmap
Bitmap generatedImageAsBitmap = imagePart.getImage();
break;
}
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
पहले
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, getImagenModel, GoogleAIBackend } from "firebase/ai";
// TODO(developer) Replace the following with your app's Firebase configuration
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create an `ImagenModel` instance with an Imagen model that supports your use case
const model = getImagenModel(ai, { model: "IMAGEN_MODEL_NAME" });
// Provide an image generation prompt
const prompt = "An astronaut riding a horse.";
// To generate an image, call `generateImages` with the text prompt
const response = await model.generateImages(prompt)
// If fewer images were generated than were requested,
// then `filteredReason` will describe the reason they were filtered out
if (response.filteredReason) {
console.log(response.filteredReason);
}
if (response.images.length == 0) {
throw new Error("No images in the response.")
}
const image = response.images[0];
बाद में
import { initializeApp } from "firebase/app";
import {
getAI,
getGenerativeModel,
GoogleAIBackend,
ResponseModality,
ImageConfigAspectRatio,
FinishReason
} from "firebase/ai";
// TODO(developer) Replace the following with your app's Firebase configuration
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "GEMINI_IMAGE_MODEL_NAME",
generationConfig: {
responseModalities: [ResponseModality.IMAGE],
imageConfig: {
aspectRatio: ImageConfigAspectRatio.LANDSCAPE_4x3
}
},
});
// Provide an image generation prompt
const prompt = "An astronaut riding a horse.";
// To generate an image, call `generateContent` with the text prompt
const result = await model.generateContent(prompt);
// Handle the generated image
try {
const response = result.response;
if (response.candidates?.[0].finishReason == FinishReason.NO_IMAGE) {
// Handle the case where no images were generated
}
const inlineDataParts = response.inlineDataParts();
if (inlineDataParts?.[0]) {
const image = inlineDataParts[0].inlineData;
// Use this mimeType and base64 data to display the image using
// your preferred tooling
console.log(image.mimeType, image.data);
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
Dart
पहले
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
final ai = FirebaseAI.googleAI();
// Create an `ImagenModel` instance with an Imagen model that supports your use case
final model = ai.imagenModel(model: 'IMAGEN_MODEL_NAME');
// Provide an image generation prompt
const prompt = 'An astronaut riding a horse.';
// To generate an image, call `generateImages` with the text prompt
final response = await model.generateImages(prompt);
if (response.images.isNotEmpty) {
final image = response.images[0];
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
बाद में
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
final ai = FirebaseAI.googleAI();
// Create a `GenerativeModel` instance with a Gemini model that supports image output
final model = ai.generativeModel(
model: 'GEMINI_IMAGE_MODEL_NAME',
generationConfig: GenerationConfig(
responseModalities: [ResponseModalities.image],
imageConfig: ImageConfig(aspectRatio: ImageAspectRatio.landscape4x3)
),
);
// Provide a text prompt instructing the model to generate an image
final prompt = [Content.text('An astronaut riding a horse.')];
// To generate an image, call `generateContent` with the text prompt
final response = await model.generateContent(prompt);
if (response.inlineDataParts.isNotEmpty) {
final imageBytes = response.inlineDataParts.first.bytes;
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
Unity
पहले
using Firebase.AI;
// Initialize the Gemini Developer API backend service
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create an `ImagenModel` instance with a model that supports your use case
var model = ai.GetImagenModel(modelName: "IMAGEN_MODEL_NAME");
// Provide an image generation prompt
var prompt = "An astronaut riding a horse";
// To generate an image, call `generateImages` with the text prompt
var response = await model.GenerateImagesAsync(prompt: prompt);
// Handle the generated image
if (response.Images.Count == 0) {
throw new Exception("No image in the response.");
}
var image = response.Images[0].AsTexture2D();
बाद में
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a Gemini model that supports image output
var model = ai.GetGenerativeModel(
modelName: "GEMINI_IMAGE_MODEL_NAME",
generationConfig: new GenerationConfig(
responseModalities: new[] { ResponseModality.Image },
imageConfig: new ImageConfig(aspectRatio: ImageConfig.AspectRatio.Landscape4x3)
)
);
// Provide an image generation prompt
var prompt = "An astronaut riding a horse";
// To generate an image, call `GenerateContentAsync` with the text prompt
var response = await model.GenerateContentAsync(prompt);
if (response.Candidates.First().FinishReason == FinishReason.NoImage) {
// Handle the case where no images were generated
}
// Handle the generated image
var imageParts = response.Candidates.First().Content.Parts
.OfType<ModelContent.InlineDataPart>()
.Where(part => part.MimeType == "image/png");
foreach (var imagePart in imageParts) {
// Load the Image into a Unity Texture2D object
UnityEngine.Texture2D texture2D = new(2, 2);
if (texture2D.LoadImage(imagePart.Data.ToArray())) {
// Do something with the image
}
}
कॉन्फ़िगरेशन के विकल्प
इस सेक्शन में, मॉडल के रिस्पॉन्स को कंट्रोल करने के लिए, मॉडल कॉन्फ़िगरेशन के अलग-अलग विकल्पों के बारे में बताया गया है.
सुरक्षा सेटिंग
Imagen मॉडल के लिए सुरक्षा सेटिंग कॉन्फ़िगर करने के लिए
ImagenSafetySettings का इस्तेमाल किया जाता है. हालांकि, Gemini इमेज मॉडल के लिए, आपको
SafetySetting का इस्तेमाल करना होगा.
मॉडल कॉन्फ़िगरेशन के पैरामीटर
Imagen मॉडल को ImagenGenerationConfig का इस्तेमाल करके कॉन्फ़िगर किया जाता है. हालांकि,
Gemini इमेज मॉडल के लिए, आपको
GenerationConfig का इस्तेमाल करना होगा. इसके अलावा, ज़रूरत पड़ने पर नेस्ट किए गए
ImageConfig
का भी इस्तेमाल किया जा सकता है. यह सुविधा, मई 2026 की शुरुआत में SDK के वर्शन से उपलब्ध है.
GenerationConfig के तहत, रिस्पॉन्स मोडैलिटी को IMAGE पर सेट करें. जैसा कि इस गाइड में पहले दिए गए "बाद में" वाले कोड सैंपल में दिखाया गया है. ध्यान दें कि आप चाहें तो
Gemini इमेज मॉडल को इस तरह कॉन्फ़िगर कर सकते हैं कि वे IMAGE और TEXT दोनों को लौटा सकें.
Imagen से Gemini इमेज मॉडल पर अपने मॉडल कॉन्फ़िगरेशन पैरामीटर को माइग्रेट करने का तरीका जानने के लिए, यहां दी गई टेबल देखें:
| Imagen मॉडल | Gemini इमेज मॉडल ("Nano Banana") |
|---|---|
addWatermark |
समर्थित नहीं Gemini इमेज मॉडल से जनरेट की गई इमेज में हमेशा SynthID वॉटरमार्क होता है. |
aspectRatio |
कोड सैंपल और काम करने वाली वैल्यू के लिए, इमेज जनरेट करने की सुविधा को कॉन्फ़िगर करना Gemini इमेज मॉडल की गाइड में देखें. |
imageFormat |
समर्थित नहीं Gemini इमेज मॉडल से जनरेट की गई इमेज हमेशा PNG फ़ॉर्मैट में होती हैं. |
negativePrompt |
समर्थित नहीं
ध्यान दें कि नेगेटिव प्रॉम्प्ट, पुरानी सुविधा है. इसे
|
numberOfImages |
समर्थित नहीं
Gemini इमेज मॉडल से हमेशा एक ही इमेज जनरेट होती है.
|
personGeneration |
समर्थित नहीं डिफ़ॉल्ट रूप से, Gemini इमेज मॉडल से लोगों की इमेज जनरेट की जा सकती हैं. |