A library for interacting with the Aparat API
Project description
GoogleLens
GoogleLens is a Python library that allows you to perform image searches using Google Lens. You can upload images via URLs, file paths, or binary data and retrieve visual match results.
Installation
You can install the library via pip:
pip install GoogleLens
Features
- Upload images from a URL, file path, or binary data.
- Extract raw text or structured visual match data from the Google Lens response.
- Retrieve the main and similar visual match results, including titles, thumbnails, and page URLs.
Usage
Uploading Images and Retrieving Results
Example 1: Upload image from URL
from googlelens import GoogleLens
# Initialize GoogleLens instance
lens = GoogleLens()
# Upload image from URL
url = "https://example.com/sample-image.jpg"
result_url = lens.upload_image(url)
# Extract and print visual match results
print("Results from URL search:")
print(result_url.extract_visual_results())
Example 2: Upload image from file path
from googlelens import GoogleLens
# Initialize GoogleLens instance
lens = GoogleLens()
# Upload image from a file path
file_path = "path/to/sample-image.jpg"
result_file = lens.upload_image(file_path)
# Extract and print visual match results
print("Results from file search:")
print(result_file.extract_visual_results())
Example 3: Upload image using bytes
from googlelens import GoogleLens
# Initialize GoogleLens instance
lens = GoogleLens()
# Read image as bytes
with open("path/to/sample-image.jpg", "rb") as f:
image_bytes = f.read()
# Upload image using bytes
result_bytes = lens.upload_image(image_bytes)
# Extract and print visual match results
print("Results from bytes search:")
print(result_bytes.extract_visual_results())
Extracting Raw Text
You can also extract raw text from the Google Lens results, if available:
# Extract raw text from the Google Lens response
raw_text = result_url.extract_raw_text()
print("Raw text extracted from the response:")
print(raw_text)
API Reference
GoogleLens
Main class to interact with Google Lens.
upload_image(image_input: Union[str, bytes]) -> GoogleLensResults- Uploads an image to Google Lens and returns the search results.
image_input: Can be a URL (str), file path (str), or binary data (bytes).
GoogleLensResults
Handles the parsing and extraction of useful data from the Google Lens response.
-
extract_visual_results() -> Dict[str, Union[None, Dict[str, str], List[Dict[str, str]]]]- Extracts the visual match results including the main match and a list of similar matches.
-
extract_raw_text() -> List[str]- Extracts raw text from the Google Lens response, if available.
Contributing
Feel free to submit issues or pull requests. Contributions are welcome!
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file googlelens-0.1.0.tar.gz.
File metadata
- Download URL: googlelens-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69c7d9b2a529d326b21b9ca13bdcc5f12de99d07da0c1ff1cb4b5588626a1d4b
|
|
| MD5 |
5f8c0915f67cae8cba4b298875c3f4ee
|
|
| BLAKE2b-256 |
7ae6347c7523ebcc5892401fd2dbf1cbd0d289035f16f9532f3fdf0b9b3e3e57
|
File details
Details for the file GoogleLens-0.1.0-py3-none-any.whl.
File metadata
- Download URL: GoogleLens-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0681dac907e10ad805ba2d5bd4ccb4e1df0e3f3943a5d1639b23e497eed33f5
|
|
| MD5 |
145875b1ff54fce22476c0de899dc383
|
|
| BLAKE2b-256 |
93b71c5d6b69b86de5d86c9e5e235e829ba0d6a6c6257251c18b51b2d8bb67de
|