ML Kit-এর GenAI Image Description API-এর সাহায্যে, আপনি ছবির জন্য সংক্ষিপ্ত বিষয়বস্তুর বিবরণ তৈরি করতে পারেন। এটি নিম্নলিখিত ব্যবহারের ক্ষেত্রে কার্যকর হতে পারে:
- ছবির শিরোনাম তৈরি করা হচ্ছে
- দৃষ্টি প্রতিবন্ধী ব্যবহারকারীদের ছবির বিষয়বস্তু আরও ভালোভাবে বুঝতে সাহায্য করার জন্য বিকল্প পাঠ্য (Alt টেক্সট) তৈরি করা
- ব্যবহারকারীদের ছবি অনুসন্ধান বা সংগঠিত করতে সাহায্য করার জন্য মেটাডেটা হিসাবে জেনারেট করা বিবরণ ব্যবহার করা
- চিত্রের সংক্ষিপ্ত বিবরণ ব্যবহার করা যখন ব্যবহারকারী তাদের স্ক্রিনের দিকে তাকাতে অক্ষম হয়, যেমন তারা যখন গাড়ি চালাচ্ছে বা পডকাস্ট শুনছে
মূল ক্ষমতা
- একটি ইনপুট চিত্রের জন্য একটি সংক্ষিপ্ত বিবরণ ফেরত দিন
উদাহরণ ফলাফল
ইনপুট | আউটপুট |
![]() | ক্যাকটাস-সদৃশ নকশা সহ একটি ছোট, সবুজ অ্যান্ড্রয়েড রোবট একটি কালো পৃষ্ঠে বসে আছে। |
![]() | কালো নাক এবং গোলাপী জিহ্বা সহ একটি ছোট, সাদা কুকুরটি পটভূমিতে একটি সেতু সহ ঘাসের মাঠ জুড়ে চলছে। |
শুরু করা
GenAI চিত্র বিবরণ API দিয়ে শুরু করতে, আপনার প্রকল্পের বিল্ড ফাইলে এই নির্ভরতা যোগ করুন।
implementation("com.google.mlkit:genai-image-description:1.0.0-beta1")
আপনার অ্যাপে চিত্র বিবরণ API একত্রিত করতে, আপনি একটি ImageDescriber
ক্লায়েন্ট পেয়ে শুরু করবেন। তারপরে আপনাকে অবশ্যই ডিভাইসে প্রয়োজনীয় মডেল বৈশিষ্ট্যগুলির স্থিতি পরীক্ষা করতে হবে এবং মডেলটি ডাউনলোড করতে হবে যদি এটি ইতিমধ্যে ডিভাইসে না থাকে। একটি ImageDescriptionRequest
এ আপনার ইমেজ ইনপুট প্রস্তুত করার পর, আপনি ক্লায়েন্ট ব্যবহার করে ইমেজ ডিসক্রিপশন টেক্সট পেতে অনুমান চালান এবং অবশেষে, রিসোর্স রিলিজ করতে ক্লায়েন্টকে বন্ধ করতে ভুলবেন না।
কোটলিন
// Create an image describer
val options = ImageDescriberOptions.builder(context).build()
val imageDescriber = ImageDescription.getClient(options)
suspend fun prepareAndStartImageDescription(
bitmap: Bitmap
) {
// Check feature availability, status will be one of the following:
// UNAVAILABLE, DOWNLOADABLE, DOWNLOADING, AVAILABLE
val featureStatus = imageDescriber.checkFeatureStatus().await()
if (featureStatus == FeatureStatus.DOWNLOADABLE) {
// Download feature if necessary.
// If downloadFeature is not called, the first inference request
// will also trigger the feature to be downloaded if it's not
// already downloaded.
imageDescriber.downloadFeature(object : DownloadCallback {
override fun onDownloadStarted(bytesToDownload: Long) { }
override fun onDownloadFailed(e: GenAiException) { }
override fun onDownloadProgress(totalBytesDownloaded: Long) {}
override fun onDownloadCompleted() {
startImageDescriptionRequest(bitmap, imageDescriber)
}
})
} else if (featureStatus == FeatureStatus.DOWNLOADING) {
// Inference request will automatically run once feature is
// downloaded.
// If Gemini Nano is already downloaded on the device, the
// feature-specific LoRA adapter model will be downloaded
// very quickly. However, if Gemini Nano is not already
// downloaded, the download process may take longer.
startImageDescriptionRequest(bitmap, imageDescriber)
} else if (featureStatus == FeatureStatus.AVAILABLE) {
startImageDescriptionRequest(bitmap, imageDescriber)
}
}
fun startImageDescriptionRequest(
bitmap: Bitmap,
imageDescriber: ImageDescriber
) {
// Create task request
val imageDescriptionRequest = ImageDescriptionRequest
.builder(bitmap)
.build()
}
// Run inference with a streaming callback
val imageDescriptionResultStreaming =
imageDescriber.runInference(imageDescriptionRequest) { outputText ->
// Append new output text to show in UI
// This callback is called incrementally as the description
// is generated
}
// You can also get a non-streaming response from the request
// val imageDescription = imageDescriber.runInference(
// imageDescriptionRequest).await().description
}
// Be sure to release the resource when no longer needed
// For example, on viewModel.onCleared() or activity.onDestroy()
imageDescriber.close()
জাভা
// Create an image describer
ImageDescriberOptions options = ImageDescriberOptions.builder(context).build();
ImageDescriber imageDescriber = ImageDescription.getClient(options);
void prepareAndStartImageDescription(
Bitmap bitmap
) throws ExecutionException, InterruptedException {
// Check feature availability, status will be one of the following:
// UNAVAILABLE, DOWNLOADABLE, DOWNLOADING, AVAILABLE
try {
int featureStatus = imageDescriber.checkFeatureStatus().get();
if (featureStatus == FeatureStatus.DOWNLOADABLE) {
// Download feature if necessary.
// If downloadFeature is not called, the first inference request
// will also trigger the feature to be downloaded if it's not
// already downloaded.
imageDescriber.downloadFeature(new DownloadCallback() {
@Override
public void onDownloadCompleted() {
startImageDescriptionRequest(bitmap, imageDescriber);
}
@Override
public void onDownloadFailed(GenAIException e) {}
@Override
public void onDownloadProgress(long totalBytesDownloaded) {}
@Override
public void onDownloadStarted(long bytesDownloaded) {}
});
} else if (featureStatus == FeatureStatus.DOWNLOADING) {
// Inference request will automatically run once feature is
// downloaded.
// If Gemini Nano is already downloaded on the device, the
// feature-specific LoRA adapter model will be downloaded
// very quickly. However, if Gemini Nano is not already
// downloaded, the download process may take longer.
startImageDescriptionRequest(bitmap, imageDescriber);
} else if (featureStatus == FeatureStatus.AVAILABLE) {
startImageDescriptionRequest(bitmap, imageDescriber);
}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
void startImageDescriptionRequest(
Bitmap bitmap,
ImageDescriber imageDescriber
) {
// Create task request
ImageDescriptionRequest imageDescriptionRequest =
ImageDescriptionRequest.builder(bitmap).build();
// Start image description request with streaming response
imageDescriber.runInference(imageDescriptionRequest, newText -> {
// Append new output text to show in UI
// This callback is called incrementally as the description
// is generated
});
// You can also get a non-streaming response from the request
// String imageDescription = imageDescriber.runInference(
// imageDescriptionRequest).get().getDescription();
}
// Be sure to release the resource when no longer needed
// For example, on viewModel.onCleared() or activity.onDestroy()
imageDescriber.close();
সমর্থিত বৈশিষ্ট্য এবং সীমাবদ্ধতা
GenAI চিত্র বিবরণ API ইংরেজি সমর্থন করে, ভবিষ্যতে আরও ভাষা যোগ করার জন্য সমর্থন সহ। API চিত্রটির একটি সংক্ষিপ্ত বিবরণ প্রদান করে।
নির্দিষ্ট বৈশিষ্ট্যের কনফিগারেশনের উপলব্ধতা ( ImageDescriberOptions
দ্বারা নির্দিষ্ট করা হয়েছে) নির্দিষ্ট ডিভাইসের কনফিগারেশন এবং ডিভাইসে ডাউনলোড করা মডেলের উপর নির্ভর করে পরিবর্তিত হতে পারে।
ডেভেলপারদের জন্য অনুরোধ করা ImageDescriberOptions
সহ একটি ডিভাইসে যে এপিআই বৈশিষ্ট্যটি সমর্থিত তা নিশ্চিত করার সবচেয়ে নির্ভরযোগ্য উপায় হল checkFeatureStatus()
পদ্ধতিতে কল করা। এই পদ্ধতিটি রানটাইমে ডিভাইসে বৈশিষ্ট্যের প্রাপ্যতার নির্দিষ্ট স্থিতি প্রদান করে।
সাধারণ সেটআপ সমস্যা
জেমিনি ন্যানো অ্যাক্সেস করতে ML Kit GenAI APIগুলি Android AICore অ্যাপের উপর নির্ভর করে। যখন একটি ডিভাইস সবেমাত্র সেটআপ করা হয় (রিসেট সহ), বা AICore অ্যাপটি রিসেট করা হয় (যেমন ডেটা পরিষ্কার, আনইনস্টল তারপর পুনরায় ইনস্টল করা হয়), তখন AICore অ্যাপের আরম্ভ করার জন্য যথেষ্ট সময় নাও থাকতে পারে (সার্ভার থেকে সর্বশেষ কনফিগারেশন ডাউনলোড করা সহ)। ফলস্বরূপ, ML Kit GenAI APIগুলি আশানুরূপ কাজ নাও করতে পারে৷ এখানে সাধারণ সেটআপ ত্রুটির বার্তাগুলি রয়েছে যা আপনি দেখতে পারেন এবং কীভাবে সেগুলি পরিচালনা করবেন:
উদাহরণ ত্রুটি বার্তা | কিভাবে হ্যান্ডেল |
AICore ত্রুটি প্রকার 4-CONNECTION_ERROR এবং ত্রুটি কোড 601-BINDING_FAILURE: AICore পরিষেবা বাঁধাই করতে ব্যর্থ হয়েছে৷ | আপনি যখন ডিভাইস সেটআপের পরপরই ML Kit GenAI API ব্যবহার করে অ্যাপটি ইনস্টল করেন বা যখন আপনার অ্যাপ ইনস্টল হওয়ার পরে AICore আনইনস্টল করা হয় তখন এটি ঘটতে পারে। AICore অ্যাপ আপডেট করার পরে আপনার অ্যাপ পুনরায় ইনস্টল করলে এটি ঠিক করা উচিত। |
AICore ত্রুটি প্রকার 3-PREPARATION_ERROR এবং ত্রুটি কোড 606-FEATURE_NOT_FOUND সহ ব্যর্থ হয়েছে: বৈশিষ্ট্য ... উপলব্ধ নেই৷ | এটি ঘটতে পারে যখন AICore সর্বশেষ কনফিগারেশন ডাউনলোড করা শেষ করেনি। নেটওয়ার্ক সংযোগ রাখুন এবং কয়েক মিনিট থেকে কয়েক ঘন্টা অপেক্ষা করুন। মনে রাখবেন যে ডিভাইসের বুটলোডার আনলক করা থাকলে, আপনি এই ত্রুটিটিও দেখতে পাবেন—এই API আনলক করা বুটলোডারগুলির সাথে ডিভাইসগুলিকে সমর্থন করে না। |
AICore ত্রুটির ধরন 1-DOWNLOAD_ERROR এবং ত্রুটি কোড 0-অজানা: বৈশিষ্ট্য ... ব্যর্থতার স্থিতি 0 এবং ত্রুটি esz সহ ব্যর্থ হয়েছে: অনুপলব্ধ: হোস্ট সমাধান করতে অক্ষম ... | নেটওয়ার্ক সংযোগ রাখুন, কয়েক মিনিট অপেক্ষা করুন এবং পুনরায় চেষ্টা করুন। |