Generative AI

Improvements of Advanced Codes: Mastering Browser-driven AI on Google Colab with Playwwright, Browser_ise Agent and BronsercoX, Langchain, and Gemini

In this lesson, we will learn how we can join Age power driven by AI driven in a completely run within Google Colab. We will use the Chromium in the Chronukright engine with a high-life-free system, and a higher browser_thal agent. We will roll the Gemino's Modemine with Langchain_Gle_genai Language Language Signs and decision-making, protected by the Pydantic privacy management of safe API-key management. With GetPass Managing Verification, Asyncio Orchestranging Unbreakable Execution, as well as funding Python-Dotenv, this setup will provide you with the final place, interacting with the agent's agent without leaving your environment.

!apt-get update -qq
!apt-get install -y -qq chromium-browser chromium-chromedriver fonts-liberation
!pip install -qq playwright python-dotenv langchain-google-generative-ai browser-use
!playwright install

We resume the list of program packages and install a headache Chromium, its WebDrium, and freedom fonts to enable the default. Then it puts the Playwwright and Python-Dotenv, Langchain-Dotinv, Langchain-Dotaining, and the use of the browser, and finally downloads the browser binavives with playwright to install.

import os
import asyncio
from getpass import getpass
from pydantic import SecretStr
from langchain_google_genai import ChatGoogleGenerativeAI
from browser_use import Agent, Browser, BrowserContextConfig, BrowserConfig
from browser_use.browser.browser import BrowserContext

We provide Python's Core resources, the OS-management of the Asynchronous Execution, as well as the Pydantic Seevatstra safe and storage. Langchain's Langchain's Gemini wrapperative) and a browser_s (agent, browserContextIn, and a browserContextT) to prepare and the Growserger agent.

os.environ["ANONYMIZED_TELEMETRY"] = "false"

We disable the reporting of unknown uses by the variable of_telemetry variable in “Fallemertry”, to ensure that no browser_the library sends any telemetry data back to its guardians.

async def setup_browser(headless: bool = True):
    browser = Browser(config=BrowserConfig(headless=headless))
    context = BrowserContext(
        browser=browser,
        config=BrowserContextConfig(
            wait_for_network_idle_page_load_time=5.0,
            highlight_elements=True,
            save_recording_path="./recordings",
        )
    )
    return browser, context

This Asynchronous helper is starting a Headed Browser. It has been returning the browser and its context to be ready for the use of your agent's functions.

async def agent_loop(llm, browser_context, query, initial_url=None):
    initial_actions = [{"open_tab": {"url": initial_url}}] if initial_url else None
    agent = Agent(
        task=query,
        llm=llm,
        browser_context=browser_context,
        use_vision=True,
        generate_gif=False,  
        initial_actions=initial_actions,
    )
    result = await agent.run()
    return result.final_result() if result else None

This Async adviser includes one “imagin-and-and-and-and-and-shaping cyclist.

async def main():
    raw_key = getpass("Enter your GEMINI_API_KEY: ")


    os.environ["GEMINI_API_KEY"] = raw_key


    api_key = SecretStr(raw_key)
    model_name = "gemini-2.5-flash-preview-04-17"


    llm = ChatGoogleGenerativeAI(model=model_name, api_key=api_key)


    browser, context = await setup_browser(headless=True)


    try:
        while True:
            query = input("nEnter prompt (or leave blank to exit): ").strip()
            if not query:
                break
            url = input("Optional URL to open first (or blank to skip): ").strip() or None


            print("n🤖 Running agent…")
            answer = await agent_loop(llm, context, query, initial_url=url)
            print("n📊 Search Resultsn" + "-"*40)
            print(answer or "No results found")
            print("-"*40)
    finally:
        print("Closing browser…")
        await browser.close()


await main()

Finally, this primary cootoutine drives up with all of the ColoB's key to your Gemino Aki key (using the Getpass and the Agent_loop work.

In conclusion, by following this guide, you now have a colab template that includes the browser's Automation, llm to consult, and security is guaranteed in single Pipeline. Whether you spread the actual time market data, summarizing news articles, defaults of reporting activities, a combination of playwwright, browser, and the Germinian display provides a variable of your next AI. Feel free to extend the power to the agent, enable custom recording, add customary recording, or switch to other llm pebbles in order to comply with your research or production requirements.


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 90k + ml subreddit.

🔥 [Register Now] Summit of the Minicon Virtual in Agentic AI: Free Registration + Certificate of Before Hour 4 Hour Court (May 21, 9 AM


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.

Source link

Related Articles

Leave a Reply

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

Back to top button