Tarsier 项目教程

Tarsier 项目教程

tarsier Vision utilities for web interaction agents 👀 tarsier 项目地址: https://gitcode.com/gh_mirrors/tarsie/tarsier

1. 项目目录结构及介绍

Tarsier项目的目录结构如下:

tarsier/
├── .github/
├── .gitignore
├── CITATION
├──/LICENSE
├── README.md
├── format.sh
├── package-lock.json
├── package.json
├── poetry.lock
├── pyproject.toml
├── tsconfig.json
├── tarsier-snapshots/
├── tests/
├── tarsier/
└── scripts/
  • .github/:包含项目的GitHub特定配置文件。
  • .gitignore:指定Git应该忽略的文件和目录。
  • CITATION:项目的引用信息。
  • /LICENSE:项目的许可文件,本项目采用MIT许可。
  • README.md:项目的自述文件,包含项目介绍和使用说明。
  • format.sh:格式化代码的脚本。
  • package-lock.jsonpackage.jsonpoetry.lockpyproject.toml:Python项目依赖管理和构建配置文件。
  • tsconfig.json:TypeScript项目的配置文件。
  • tarsier-snapshots/:存储页面快照的目录。
  • tests/:存放测试文件的目录。
  • tarsier/:Tarsier库的核心代码目录。
  • scripts/:存放项目脚本的目录。

2. 项目的启动文件介绍

项目的启动主要是通过main.py文件进行的,该文件通常位于tarsier/目录下。以下是启动文件的基本内容:

import asyncio
from playwright.async_api import async_playwright
from tarsier import Tarsier, GoogleVisionOCRService

async def main():
    google_cloud_credentials = {
        # 从这里加载Google Cloud的凭证
    }
    ocr_service = GoogleVisionOCRService(google_cloud_credentials)
    tarsier = Tarsier(ocr_service)

    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        page = await browser.new_page()
        await page.goto("https://news.ycombinator.com")
        
        page_text, tag_to_xpath = await tarsier.page_to_text(page)
        print(tag_to_xpath)
        print(page_text)

if __name__ == "__main__":
    asyncio.run(main())

这个脚本的主要功能是启动一个异步的Playwright浏览器实例,然后访问指定的网页,并使用Tarsier库将页面内容转换成文本表示形式。

3. 项目的配置文件介绍

项目的配置主要通过pyproject.toml文件进行,这是一个用于配置Python项目和其依赖的文件。以下是配置文件的基本内容:

[tool.poetry]
name = "tarsier"
version = "0.1.0"
description = "Vision utilities for web interaction agents"
authors = ["Rohan Pandey <rohan@reworkd.ai>", "Adam Watkins <adam@reworkd.ai>"]

[tool.poetry.dependencies]
python = "^3.8"
playwright = "^1.18.2"
pytest = "^6.2.5"
pydantic = "^1.8.2"
aiohttp = "^3.7.4"
asyncio = "*"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"

这个配置文件指定了项目名称、版本、描述、作者和项目的依赖项。使用poetry工具可以方便地管理项目的依赖关系,并构建项目环境。

tarsier Vision utilities for web interaction agents 👀 tarsier 项目地址: https://gitcode.com/gh_mirrors/tarsie/tarsier

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

齐添朝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值