-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
accb18c
commit 3aaf9f6
Showing
8 changed files
with
315 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules/** | |
pnpm-lock.yaml | ||
renovate.json | ||
.gitignore | ||
.github/**/* | ||
.github/**/* | ||
.prettierrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,144 @@ | ||
# Exif AI | ||
|
||
*Exif AI* is a CLI tool for writing AI-generated image descriptions to metadata. | ||
_Exif AI_ is a powerful CLI tool designed to write AI-generated image descriptions directly into the metadata of image files. This tool leverages advanced AI models to analyze image content and generate descriptive metadata, enhancing the accessibility and searchability of your images. | ||
|
||
## Usage Example | ||
|
||
Without Installation | ||
### CLI | ||
|
||
#### Without Installation | ||
|
||
You can run Exif AI directly using npx without installing it globally: | ||
|
||
```bash | ||
ZHIPUAI_API_KEY=Your_Key npx exif-ai -i example.jpeg -a zhipu | ||
npx exif-ai -i example.jpeg -a ollama | ||
``` | ||
|
||
With Installation | ||
#### With Installation | ||
|
||
If you have installed Exif AI globally, you can run it directly from the command line: | ||
|
||
```bash | ||
ZHIPUAI_API_KEY=Your_Key exif-ai -i example.jpeg -a zhipu | ||
exif-ai -i example.jpeg -a ollama | ||
``` | ||
|
||
#### Options | ||
|
||
Required options: | ||
|
||
- `-i, --input <value>` Path to the input image file. | ||
- `-a, --api-provider <value>` Name of the AI provider to use (`ollama` for Ollama or `zhipu` for ZhipuAI). | ||
|
||
Optional options: | ||
|
||
- `-p, --prompt [value]`: Custom prompt for the AI provider. Defaults to a generic image description prompt. | ||
- `-m, --model [value]`: Specify the AI model to use, if supported by the provider. | ||
- `-t, --tags [value...]`: EXIF tags to write the description to. Defaults to common description tags. | ||
- `-v, --verbose`: Enable verbose output for debugging. | ||
- `-d, --dry-run`: Preview the AI-generated description without writing to the image file. | ||
- `--exif-tool-write-args [value...]`: Additional ExifTool arguments for writing metadata. | ||
- `--provider-args [value...]`: Additional arguments for the AI provider. | ||
|
||
Example usage: | ||
|
||
```bash | ||
exif-ai -i example.jpg -a ollama -p "Describe this landscape photo." | ||
``` | ||
|
||
### Library | ||
|
||
To use Exif AI as a library in your project, import it and use the provided functions: | ||
|
||
```typescript | ||
import { execute } from "exif-ai"; | ||
|
||
const options = { | ||
path: "example.jpeg", | ||
provider: "ollama", | ||
model: "moondream", // Optional: specify the model if required by the provider | ||
tags: ["XPComment", "Description", "ImageDescription", "Caption-Abstract"], // Optional: specify the EXIF tags to write | ||
prompt: "请使用中文描述这个图片。", // Optional: specify the prompt for the AI provider | ||
verbose: false, // Optional: enable verbose logging | ||
dry: false, // Optional: perform a dry run without writing to the file | ||
writeArgs: [], // Optional: additional arguments for EXIF write task | ||
providerArgs: [], // Optional: additional arguments for the AI provider | ||
}; | ||
execute(options) | ||
.then(() => { | ||
console.log("Image description has been written to EXIF metadata."); | ||
}) | ||
.catch((error) => { | ||
console.error("An error occurred:", error); | ||
}); | ||
``` | ||
|
||
## Installation | ||
|
||
To install Exif AI globally, use the following command: | ||
|
||
```bash | ||
npm install -g exif-ai | ||
``` | ||
|
||
## API Providers | ||
|
||
Exif AI requires an API provider to generate descriptions from images. Currently, we have only one built-in provider, ZhipuAI. You should have a ZhipuAI API key before using Exif AI. | ||
Exif AI relies on API providers to generate image descriptions. Currently, we support two providers: ZhipuAI and Ollama. | ||
|
||
### Supported Providers | ||
|
||
ZhipuAI: A leading AI service provider. Requires an API key. | ||
Ollama: A local AI service that runs on your machine, eliminating the need for an API key. | ||
|
||
### Custom Providers | ||
|
||
You can also develop your own custom provider by implementing the provider interface. This allows you to integrate with other AI services or customize the description generation process. | ||
|
||
You can also build your own provider by implementing the provider interface. | ||
## Configuration | ||
|
||
### Setting API Keys (for ZhipuAI) | ||
|
||
To use ZhipuAI, you need to set the API key. You can do this by setting an environment variable: | ||
|
||
```bash | ||
export ZHIPUAI_API_KEY=your_zhipuai_api_key | ||
``` | ||
|
||
### Ollama Configuration | ||
|
||
Ollama runs locally and does not require an API key. Ensure that Ollama is installed and properly configured on your machine. Refer to the [Ollama GitHub repository](https://github.com/ollama/ollama) for installation and setup instructions. | ||
|
||
## Develop | ||
|
||
1. Clone the Repository | ||
### Prerequisites | ||
|
||
- Node.js >=18 | ||
- pnpm | ||
|
||
### Clone the Repository | ||
|
||
First, clone the Exif AI repository to your local machine: | ||
|
||
```bash | ||
git clone https://github.com/tychenjiajun/exif-ai.git | ||
cd exif-ai | ||
``` | ||
|
||
2. Install Dependencies | ||
### Install Dependencies | ||
|
||
Next, install the required dependencies using `pnpm`. | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
|
||
### Build | ||
|
||
```bash | ||
pnpm run build | ||
``` | ||
|
||
### Watch | ||
|
||
```bash | ||
pnpm run watch | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# NAME | ||
|
||
exif-ai - Write AI-generated image descriptions to EXIF metadata. | ||
|
||
# SYNOPSIS | ||
|
||
``` | ||
exif-ai [options] | ||
``` | ||
|
||
# DESCRIPTION | ||
|
||
The `exif-ai` command is a Node.js CLI tool that uses AI to analyze image content and write descriptive metadata to the EXIF information of an image file. It supports two AI providers: Ollama and ZhipuAI. Ollama runs locally, while ZhipuAI requires an API key. | ||
|
||
# OPTIONS | ||
|
||
* `-i, --input <file>`: | ||
Specify the path to the input image file. | ||
|
||
* `-a, --api-provider <name>`: | ||
Choose the AI provider to use. Acceptable values are ollama or zhipu. | ||
|
||
* `-p, --prompt <text>`: | ||
Set a custom prompt for the AI provider. If not specified, a default prompt is used. | ||
|
||
* `-m, --model <name>`: | ||
Specify the AI model to use, if supported by the provider. | ||
|
||
* `-t, --tags <tags...>`: | ||
List the EXIF tags to write the description to. Defaults to common description tags if not specified. | ||
|
||
* `-v, --verbose`: | ||
Enable verbose output for debugging. | ||
|
||
* `-d, --dry-run`: | ||
Preview the AI-generated description without writing to the image file. | ||
|
||
* `--exif-tool-write-args <args...>`: | ||
Provide additional arguments for ExifTool when writing metadata. | ||
|
||
* `--provider-args <args...>`: | ||
Pass additional arguments to the AI provider. | ||
|
||
# EXAMPLES | ||
|
||
Write a description to an image using Ollama: | ||
|
||
``` | ||
exif-ai -i image.jpg -a ollama | ||
``` | ||
|
||
Use ZhipuAI with a custom prompt: | ||
|
||
``` | ||
exif-ai -i image.jpg -a zhipu -p "Describe the scenery in this photo." | ||
``` | ||
|
||
Perform a dry run to see the description without modifying the image: | ||
|
||
``` | ||
exif-ai -i image.jpg -a ollama -d | ||
``` | ||
|
||
# PROVIDERS | ||
|
||
* Ollama: | ||
A local AI service that runs on your machine. No API key is required. | ||
|
||
* ZhipuAI: | ||
An AI service provider that requires an API key. Set the environment variable ZHIPUAI_API_KEY with your key. | ||
|
||
# CONFIGURATION | ||
|
||
For ZhipuAI, set the API key using an environment variable: | ||
|
||
``` | ||
export ZHIPUAI_API_KEY=your_zhipuai_api_key | ||
``` | ||
|
||
Ensure Ollama is installed and configured on your machine. Refer to the Ollama GitHub repository for installation and setup instructions. | ||
|
||
# DEVELOPMENT | ||
To contribute to Exif AI, clone the repository, install dependencies, and build the project: | ||
|
||
``` | ||
git clone https://github.com/tychenjiajun/exif-ai.git | ||
cd exif-ai | ||
pnpm install | ||
pnpm run build | ||
``` | ||
|
||
# LICENSE | ||
|
||
Exif AI is licensed under the GPL-2.0-only License. | ||
|
||
# SEE ALSO | ||
* exiftool-vendored (https://github.com/photostructure/exiftool-vendored.js) | ||
* ollama (https://github.com/ollama/ollama) | ||
* zhipuAI (https://zhipu.ai) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.