Gemini API ব্যবহার করে নথিগুলি (যেমন PDF) বিশ্লেষণ করুন৷

আপনি একটি জেমিনি মডেলকে ডকুমেন্ট ফাইলগুলি (যেমন পিডিএফ এবং প্লেইন-টেক্সট ফাইল) বিশ্লেষণ করতে বলতে পারেন যা আপনি ইনলাইন (বেস64-এনকোডেড) বা URL এর মাধ্যমে প্রদান করেন। আপনি যখন Firebase AI Logic ব্যবহার করেন, তখন আপনি সরাসরি আপনার অ্যাপ থেকে এই অনুরোধ করতে পারেন।

এই ক্ষমতা দিয়ে, আপনি এই ধরনের কাজ করতে পারেন:

  • নথির ভিতরে ডায়াগ্রাম, চার্ট এবং টেবিল বিশ্লেষণ করুন
  • কাঠামোগত আউটপুট ফরম্যাটে তথ্য বের করুন
  • নথিতে ভিজ্যুয়াল এবং পাঠ্য বিষয়বস্তু সম্পর্কে প্রশ্নের উত্তর দিন
  • নথিগুলি সংক্ষিপ্ত করুন
  • নথির বিষয়বস্তু ট্রান্সক্রাইব করুন (উদাহরণস্বরূপ, HTML-এ), বিন্যাস এবং বিন্যাস সংরক্ষণ, ডাউনস্ট্রিম অ্যাপ্লিকেশনগুলিতে ব্যবহারের জন্য (যেমন RAG পাইপলাইনে)

কোডের নমুনাগুলিতে ঝাঁপ দাও প্রবাহিত প্রতিক্রিয়াগুলির জন্য কোডে ঝাঁপ দাও


নথিগুলির সাথে কাজ করার জন্য অতিরিক্ত বিকল্পগুলির জন্য অন্যান্য গাইড দেখুন (যেমন পিডিএফ)
স্ট্রাকচার্ড আউটপুট মাল্টি-টার্ন চ্যাট তৈরি করুন

আপনি শুরু করার আগে

এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট সামগ্রী এবং কোড দেখতে আপনার Gemini API প্রদানকারীতে ক্লিক করুন।

যদি আপনি ইতিমধ্যে না করে থাকেন, শুরু করার নির্দেশিকাটি সম্পূর্ণ করুন, যা বর্ণনা করে যে কীভাবে আপনার Firebase প্রকল্প সেট আপ করবেন, আপনার অ্যাপকে Firebase-এ সংযুক্ত করবেন, SDK যোগ করবেন, আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য ব্যাকএন্ড পরিষেবা শুরু করবেন এবং একটি GenerativeModel উদাহরণ তৈরি করবেন।

আপনার প্রম্পটে পরীক্ষা এবং পুনরাবৃত্তি করার জন্য এবং এমনকি একটি জেনারেট করা কোড স্নিপেট পাওয়ার জন্য, আমরা Google AI Studio ব্যবহার করার পরামর্শ দিই।

পিডিএফ ফাইল থেকে পাঠ্য তৈরি করুন (বেস64-এনকোডেড)

এই নমুনাটি চেষ্টা করার আগে, আপনার প্রকল্প এবং অ্যাপ সেট আপ করতে এই গাইডের শুরু করার আগে বিভাগটি সম্পূর্ণ করুন।
সেই বিভাগে, আপনি আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য একটি বোতামে ক্লিক করবেন যাতে আপনি এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট সামগ্রী দেখতে পান

আপনি একটি মিথুন মডেলকে টেক্সট এবং পিডিএফ-এর সাথে প্রম্পট করে টেক্সট তৈরি করতে বলতে পারেন- প্রতিটি ইনপুট ফাইলের mimeType এবং ফাইল নিজেই প্রদান করে। এই পৃষ্ঠায় পরে ইনপুট ফাইলের জন্য প্রয়োজনীয়তা এবং সুপারিশ খুঁজুন।

সুইফট

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে generateContent() কল করতে পারেন।


import FirebaseAI

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-2.0-flash")


// Provide the PDF as `Data` with the appropriate MIME type
let pdf = try InlineDataPart(data: Data(contentsOf: pdfURL), mimeType: "application/pdf")

// Provide a text prompt to include with the PDF file
let prompt = "Summarize the important results in this report."

// To generate text output, call `generateContent` with the PDF file and text prompt
let response = try await model.generateContent(pdf, prompt)

// Print the generated text, handling the case where it might be nil
print(response.text ?? "No text in response.")

Kotlin

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে generateContent() কল করতে পারেন।

কোটলিনের জন্য, এই SDK-এর পদ্ধতিগুলি হল সাসপেন্ড ফাংশন এবং একটি Coroutine স্কোপ থেকে কল করা প্রয়োজন৷

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-2.0-flash")


val contentResolver = applicationContext.contentResolver

// Provide the URI for the PDF file you want to send to the model
val inputStream = contentResolver.openInputStream(pdfUri)

if (inputStream != null) {  // Check if the PDF file loaded successfully
    inputStream.use { stream ->
        // Provide a prompt that includes the PDF file specified above and text
        val prompt = content {
            inlineData(
                bytes = stream.readBytes(),
                mimeType = "application/pdf" // Specify the appropriate PDF file MIME type
            )
            text("Summarize the important results in this report.")
        }

        // To generate text output, call `generateContent` with the prompt
        val response = generativeModel.generateContent(prompt)

        // Log the generated text, handling the case where it might be null
        Log.d(TAG, response.text ?: "")
    }
} else {
    Log.e(TAG, "Error getting input stream for file.")
    // Handle the error appropriately
}

Java

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে generateContent() কল করতে পারেন।

জাভার জন্য, এই SDK-এর পদ্ধতিগুলি একটি ListenableFuture প্রদান করে।

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-2.0-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);


ContentResolver resolver = getApplicationContext().getContentResolver();

// Provide the URI for the PDF file you want to send to the model
try (InputStream stream = resolver.openInputStream(pdfUri)) {
    if (stream != null) {
        byte[] audioBytes = stream.readAllBytes();
        stream.close();

        // Provide a prompt that includes the PDF file specified above and text
        Content prompt = new Content.Builder()
              .addInlineData(audioBytes, "application/pdf")  // Specify the appropriate PDF file MIME type
              .addText("Summarize the important results in this report.")
              .build();

        // To generate text output, call `generateContent` with the prompt
        ListenableFuture<GenerateContentResponse> response = model.generateContent(prompt);
        Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
            @Override
            public void onSuccess(GenerateContentResponse result) {
                String text = result.getText();
                Log.d(TAG, (text == null) ? "" : text);
            }
            @Override
            public void onFailure(Throwable t) {
                Log.e(TAG, "Failed to generate a response", t);
            }
        }, executor);
    } else {
        Log.e(TAG, "Error getting input stream for file.");
        // Handle the error appropriately
    }
} catch (IOException e) {
    Log.e(TAG, "Failed to read the pdf file", e);
} catch (URISyntaxException e) {
    Log.e(TAG, "Invalid pdf file", e);
}

Web

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে generateContent() কল করতে পারেন।


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
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-2.0-flash" });


// Converts a File object to a Part object.
async function fileToGenerativePart(file) {
  const base64EncodedDataPromise = new Promise((resolve) => {
    const reader = new FileReader();
    reader.onloadend = () => resolve(reader.result.split(','));
    reader.readAsDataURL(file);
  });
  return {
    inlineData: { data: await base64EncodedDataPromise, mimeType: file.type },
  };
}

async function run() {
  // Provide a text prompt to include with the PDF file
  const prompt = "Summarize the important results in this report.";

  // Prepare PDF file for input
  const fileInputEl = document.querySelector("input[type=file]");
  const pdfPart = await fileToGenerativePart(fileInputEl.files);

  // To generate text output, call `generateContent` with the text and PDF file
  const result = await model.generateContent([prompt, pdfPart]);

  // Log the generated text, handling the case where it might be undefined
  console.log(result.response.text() ?? "No text in response.");
}

run();

Dart

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে generateContent() কল করতে পারেন।


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
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-2.0-flash');


// Provide a text prompt to include with the PDF file
final prompt = TextPart("Summarize the important results in this report.");

// Prepare the PDF file for input
final doc = await File('document0.pdf').readAsBytes();

// Provide the PDF file as `Data` with the appropriate PDF file MIME type
final docPart = InlineDataPart('application/pdf', doc);

// To generate text output, call `generateContent` with the text and PDF file
final response = await model.generateContent([
  Content.multi([prompt,docPart])
]);

// Print the generated text
print(response.text);

ঐক্য

আপনি টেক্সট এবং PDF এর মাল্টিমোডাল ইনপুট থেকে টেক্সট তৈরি করতে GenerateContentAsync() কল করতে পারেন।


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 model that supports your use case
var model = ai.GetGenerativeModel(modelName: "gemini-2.0-flash");


// Provide a text prompt to include with the PDF file
var prompt = ModelContent.Text("Summarize the important results in this report.");

// Provide the PDF file as `data` with the appropriate PDF file MIME type
var doc = ModelContent.InlineData("application/pdf",
      System.IO.File.ReadAllBytes(System.IO.Path.Combine(
        UnityEngine.Application.streamingAssetsPath, "document0.pdf")));

// To generate text output, call `GenerateContentAsync` with the text and PDF file
var response = await model.GenerateContentAsync(new [] { prompt, doc });

// Print the generated text
UnityEngine.Debug.Log(response.Text ?? "No text in response.");

আপনার ব্যবহারের ক্ষেত্রে এবং অ্যাপের জন্য উপযুক্ত একটি মডেল কীভাবে চয়ন করবেন তা শিখুন।

প্রতিক্রিয়া স্ট্রীম

এই নমুনাটি চেষ্টা করার আগে, আপনার প্রকল্প এবং অ্যাপ সেট আপ করতে এই গাইডের শুরু করার আগে বিভাগটি সম্পূর্ণ করুন।
সেই বিভাগে, আপনি আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য একটি বোতামে ক্লিক করবেন যাতে আপনি এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট সামগ্রী দেখতে পান

আপনি মডেল জেনারেশন থেকে সম্পূর্ণ ফলাফলের জন্য অপেক্ষা না করে দ্রুত মিথস্ক্রিয়া অর্জন করতে পারেন এবং পরিবর্তে আংশিক ফলাফল পরিচালনা করতে স্ট্রিমিং ব্যবহার করতে পারেন। প্রতিক্রিয়া স্ট্রিম করতে, generateContentStream কল করুন।



ইনপুট নথির জন্য প্রয়োজনীয়তা এবং সুপারিশ

মনে রাখবেন যে ইনলাইন ডেটা হিসাবে প্রদত্ত একটি ফাইল ট্রানজিটে বেস64 এ এনকোড করা হয়, যা অনুরোধের আকার বাড়ায়। একটি অনুরোধ খুব বড় হলে আপনি একটি HTTP 413 ত্রুটি পাবেন।

নিম্নলিখিত বিষয়ে বিস্তারিত তথ্য জানতে " Vertex AI Gemini API-এর জন্য সমর্থিত ইনপুট ফাইল এবং প্রয়োজনীয়তা" দেখুন:

সমর্থিত ভিডিও MIME প্রকার

জেমিনি মাল্টিমোডাল মডেলগুলি নিম্নলিখিত নথি MIME প্রকারগুলিকে সমর্থন করে:

নথি MIME প্রকার Gemini 2.0 Flash Gemini 2.0 Flash-Lite
পিডিএফ - application/pdf
টেক্সট - text/plain

অনুরোধ প্রতি সীমা

পিডিএফগুলিকে চিত্র হিসাবে বিবেচনা করা হয়, তাই একটি পিডিএফের একক পৃষ্ঠাকে একটি চিত্র হিসাবে বিবেচনা করা হয়। একটি প্রম্পটে অনুমোদিত পৃষ্ঠার সংখ্যা মডেলটি সমর্থন করতে পারে এমন চিত্রগুলির সংখ্যার মধ্যে সীমাবদ্ধ:

  • Gemini 2.0 Flash এবং Gemini 2.0 Flash-Lite :
    • অনুরোধ প্রতি সর্বোচ্চ ফাইল: 3,000
    • ফাইল প্রতি সর্বোচ্চ পৃষ্ঠা: 1,000
    • ফাইল প্রতি সর্বোচ্চ আকার: 50 MB



আপনি আর কি করতে পারেন?

  • মডেলে দীর্ঘ প্রম্পট পাঠানোর আগে কীভাবে টোকেন গণনা করবেন তা শিখুন।
  • Cloud Storage for Firebase সেট আপ করুন যাতে আপনি আপনার মাল্টিমোডাল অনুরোধগুলিতে বড় ফাইলগুলি অন্তর্ভুক্ত করতে পারেন এবং প্রম্পটে ফাইলগুলি সরবরাহ করার জন্য আরও পরিচালিত সমাধান পেতে পারেন৷ ফাইলগুলিতে ছবি, পিডিএফ, ভিডিও এবং অডিও অন্তর্ভুক্ত থাকতে পারে।
  • উত্পাদনের জন্য প্রস্তুতির বিষয়ে চিন্তা করা শুরু করুন ( উৎপাদন চেকলিস্ট দেখুন), সহ:

অন্যান্য ক্ষমতা ব্যবহার করে দেখুন

বিষয়বস্তু তৈরি নিয়ন্ত্রণ কিভাবে শিখুন

আপনি প্রম্পট এবং মডেল কনফিগারেশন নিয়ে পরীক্ষা করতে পারেন এবং এমনকি Google AI Studio ব্যবহার করে একটি জেনারেট করা কোড স্নিপেট পেতে পারেন।

সমর্থিত মডেল সম্পর্কে আরও জানুন

বিভিন্ন ব্যবহারের ক্ষেত্রে উপলব্ধ মডেল এবং তাদের কোটা এবং মূল্য সম্পর্কে জানুন।


Firebase AI লজিকের সাথে আপনার অভিজ্ঞতা সম্পর্কে মতামত দিন