Generative AI

Ukusetshenziswa kwekhodi ukwakha uhlelo lokusebenzisana lwe-AI-Powered PDF ku-Google Colab usebenzisa i-Gemini Flash 1.5, Pymupddf, kanye ne-Google Orandative AI API

In this lesson, we show how to build a PDF usage program on Google Colab using Gemini Flash 1.5, Pymupdf, and Google API AI API API API API API API API API API API API API API API API API API API API API API API API API API. By installing tools, we can download without sewing the PDF, and asks its text, and ask questions, we find smart answers from the latest Gemin Fash 1.5 model.

!pip install -q -U google-generativeai PyMuPDF python-dotenv

First we include the required dependency on the creation of the PDF Q & AI-Powered Ai Q & on Google Colab. Google-Generativeai provides access to Gemini Flash 1.5, enables the natural language interaction, while the Pymupdf (known as FITZ) allows the active deletion from PDFs. Also, Python-Dotenv is helping natural variations, such as API buttons, safely inside the booklet.

from google.colab import files
uploaded = files.upload()

We upload files from your location device to Google Colab. When killed, it opens the file selection box, allowing you to select a file (eg PDF) to upload. The loaded file is stored in the object such as dictionary (loaded), where the keys represent the keywords and numbers containing binary data. This step is important to process specific documents, datasets, or metal instruments in the colob area.

import fitz


def extract_pdf_text(pdf_path):
    doc = fitz.open(pdf_path)
    full_text = ""
    for page in doc:
        full_text += page.get_text()
    return full_text


pdf_file_path="/content/Paper.pdf"
document_text = extract_pdf_text(pdf_path=pdf_file_path)
print("Document text extracted!")
print(document_text[:1000]) 

We use Pymupf (FITZ) to remove text from PDF file on Google Colab. The work released by PPDF_TEXT (PDF_PATH) Reads PDF, Itemates on its pages, and returns the contents of the text. The issued text is held in the document_text, in the first 1000 letters printed to preview the content. This step is important to empower the text-based analysis and answer the question AI from PDFs.

import os
os.environ["GOOGLE_API_KEY"] = 'Use your own API key here'

We put the Google API key such as natural flexibility on Google Colab. The API key is asked to confirm applications on Google Generative Ai, which allows access to Gemini Flash 1.5 access to the Powerful AI text processing. Instead of 'Use your API key here' with a valid key confirming that the model can generate the answers safely within the letter of writing.

import google.generativeai as genai


genai.configure(api_key=os.environ["GOOGLE_API_KEY"])


model_name = "models/gemini-1.5-flash-001"


def query_gemini_flash(question, context):
    model = genai.GenerativeModel(model_name=model_name)
    prompt = f"""
Context: {context[:20000]}


Question: {question}


Answer:
"""
    response = model.generate_content(prompt)
    return response.text


pdf_text = extract_pdf_text("/content/Paper.pdf")


question = "Summarize the key findings of this document."
answer = query_gemini_flash(question, pdf_text)
print("Gemini Flash Answer:")
print(answer)

Finally, we are preparing and asking and asking Gemini Flash 1.5 using a PDF document for Ai-Powed Stund. Starts the Genai Library with an API key and loading the Femini Flash 1.5 (Gemini-1.5-flash-001). Question_Gamini_flash () The work is taking the question and the PDF text released as installation, decreasing immediately, and returns the AI ​​response. This setup enables the automatic documentation of the document and Q & A Desert of PDFS.

In conclusion, following this lesson, provided the PDF interactions based on the PDF in Google Colab using Gemini Flash 1.5, Pymupdf, and Google API AI API API API API API API API API API API API API API API API API API API API API API. This solution enables users to issue information from PDFs and always be clearly pure. A combination of Google's cutting systems and the Colon cutting environment provides a stronger and accessible process of processing large documents without requiring heavy computer resources.


Here is the Colab Notebook. Also, don't forget to follow Sane and join ours Telegraph station including LinkedIn Grtopic. Don't forget to join ours 80k + ml subreddit.


Asphazzaq is a Markteach Media Inc. According to a View Business and Developer, Asifi is committed to integrating a good social intelligence. His latest attempt is launched by the launch of the chemistrylife plan for an intelligence, MarktechPost, a devastating intimate practice of a machine learning and deep learning issues that are clearly and easily understood. The platform is adhering to more than two million moon visits, indicating its popularity between the audience.

Parlint: Create faithful AI customers facing agents with llms 💬 ✅ (encouraged)

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button