opai

package module
v0.0.0-...-c35f72a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

README

Open Photo AI (OPAI)

Open Photo AI (OPAI)
Open Photo AI is an open source alternative to the popular photo AI editor.
It currently supports the following enhancements:

💡 Motivation

There are many excellent AI-based photo editing tools available today, ranging from open-source solutions – often powerful but complex to set up and use, such as ComfyUI – to commercial products that favor ease of use over deep customization, like those from Topaz Labs.

I have long used both ComfyUI and Topaz Labs solutions, choosing between them depending on the task. Recently, however, Topaz Labs moved from a perpetual license to a subscription-based pricing model, a change I strongly dislike. As a developer, I am happy to pay for software that is useful for me, whether open source or proprietary, but I believe subscription models are rarely designed to benefit users and instead primarily serve company interests.

That is why I created this project: an open-source alternative to Topaz Photo AI. It may never match the same level of polish or performance – Topaz has teams of full-time engineers, while this is a solo project built in my spare time – but I have ambitious goals and aim to reach feature parity with their product over time.

🖼️ Usage

There are two ways to use Open Photo AI: using the GUI or the CLI.

The GUI is the easiest way to use the app, with an intuitive interface that allows you to enhance images with just a few clicks. The CLI is more advanced and allows you to enhance images in a more automated way.

Both versions are available for Windows, macOS, and Linux. Download the latest release that matches your computer architecture and operating system and follow the instructions below:

GUI (video 🎥)

Open Photo AI - GUI

  1. Click on the button Browse images to select one or more images that you would like to enhance.
  2. The images are enhanced automatically or manually depending on the toggle Autopilot in the top right side of the screen:
    • If enabled, the app will automatically analyse the images and suggest enhancements for them.
    • If disabled, you will need to select the enhancements yourself, using the button Add enhancement.
  3. Select one or more images that you would like to export on the image drawer at the bottom of the screen.
  4. Click on the button Export image, select the location and image format, then click on Export.
CLI

Coming soon...

✨ Enhancements

All enhancements available here come from open-source AI models that were adapted and converted to work on this project. The models and the credits to the original works can be found in the Hugging Face repository vegidio/open-photo-ai:

Face Recovery
  • Athens: use when identity fidelity matters most. This model lets you preserve facial structure while restoring details, even on heavily degraded faces. Best when you want restoration without changing the person.
  • Santorini: use when you want aggressive, fast enhancement and can tolerate identity drift. It produces sharp, visually pleasing faces on moderate degradation, but may hallucinate features and alter identity on very low-quality inputs.

Verdict: if identity matters, start with Athens; if aesthetics matter more, use Santorini.

Light Adjustment
  • Paris: use when working with images affected by poor or uneven lighting, such as night scenes, backlit photos, shadows, or overexposed areas. It’s useful when you need to enhance visibility and contrast so that images look clearer.
Upscale
  • Tokyo: use when you want a natural upscale without exaggeration. It focuses on preserving the original look and fine structures instead of "inventing" new details, making it ideal when realism and faithfulness matter more than sharpness.
  • Kyoto: use for real-world photos (people, landscapes, products). It excels at restoring details while handling noise, blur, and compression artifacts. Ideal for practical applications where images are imperfect, and you want visually pleasing, robust results fast.
  • Saitama: use for cartoon, drawings, line art, and digital illustrations. It preserves clean lines, flat colors, and stylized shading without introducing photo-like textures. Best when sharp edges and stylistic consistency matter more than realism.

Verdict: start with Tokyo, then try Kyoto if the result looks too soft.

🛣️ Roadmap

These are the features I plan to implement in the future, in no particular order:

  • Model selection and enhancements customization.
  • Support different preview layouts.
  • Add new model for light adjustment.
  • Add app preferences so you don't have to configure them every time.
  • Enable TensorRT acceleration when pre warm-up is implemented.
  • Crop and rotate images in the GUI.
  • Add new models for denoise, sharpening, and color correction.
  • Add new model to colorize black and white photos.
  • Add new model to fix imperfections and remove objects from photos.
  • Simplify the app installation using packages and installers.
  • Attempt to include diffusion-based models (this will be hard!)
  • CLI implementation.
  • Improve documentation for the library.
  • Internationalization to other languages.

💣 Troubleshooting

"App Is Damaged/Blocked..." (Windows & macOS only)

For a couple of years now, Microsoft and Apple have required developers to join their "Developer Program" to gain the pretentious status of an identified developer 😛.

Translating to non-BS language, this means that if you’re not registered with them (i.e., paying the fee), you can’t freely distribute Windows or macOS software. Apps from unidentified developers will display a message saying the app is damaged or blocked and can’t be opened.

To bypass this, open the Terminal and run one of the commands below (depending on your operating system), replacing <path-to-app> with the correct path to where you’ve installed the app:

  • Windows: Unblock-File -Path <path-to-app>
  • macOS: xattr -d com.apple.quarantine <path-to-app>
"Error loading libraries: libwebkit2gtk-4.1.so..." (Linux only)

To run the GUI version of the app on Linux, you will need to install the following dependencies: libgtk and libwebkit2gtk. To do that, open your terminal and run the following command, depending on your distribution:

  • Debian/Ubuntu: sudo apt install libgtk-3-0 libwebkit2gtk-4.1-0
  • Fedora 40+: sudo dnf install gtk3 webkit2gtk4.1
  • Arch Linux: sudo pacman -S gtk3 webkit2gtk-4.1
  • openSUSE: sudo zypper install libgtk-3-0 libwebkit2gtk-4_1-0
The app is taking too long to download dependencies

This app has some important dependencies that can't be bundled with the app itself because they are rather big, like ONNX Runtime, CUDA and TensorRT (if supported by your system). They are hosted on Github and the app will download them the first time it opens.

Unfortunately, Github has a rate limit that will throttle the download speed if these files are downloaded too frequently. Since this is an open-source and free project I can't afford to pay for a hosted solution where we wouldn't have this problem.

If someday this project receives enough funds/donations then I will pay for a better hosting solution. Meanwhile, bare with me on this one.

The model is taking too long to load (TensorRT only)

When you open the app for the first time, if it detects that TensorRT is available on your system, it will prompt you to enable it or not. If you choose to enable it, all models will run with TensorRT acceleration.

This is one of the fastest ways to run the models, however TensorRT needs to optimize the model graphs the first time it's used, which can take a few minutes. This is why it seems to be taking too long or even stuck when you run the models for the first time. But on subsequent runs, when the TensorRT optimization is already done, all enhancements will run much faster.

If you don't want to use TensorRT acceleration, you can disable it in the app Settings.

🐞 Known Issues

  1. Using half-precision (FP16) models with CPU execution provider often doesn't give any performance boost; a bug fix for this is expected to be available in the next ONNX release.
  2. The ONNX Runtime has a bug when running half-precision (FP16) models on Apple's M-series chip; a bug fix for this is expected to be available in the next ONNX release. Meanwhile, all image processing on Macs will be done in full precision, which gives the best quality possible, but it's often unnecessarily slow.
  3. The Tokyo model doesn't work with Apple's CoreML. This is a limitation on CoreML's architecture, so any upscaling using this model on a Mac will be slow.

🛠️ Build

Dependencies

To build this project, you will need the following dependencies installed in your computer:

If you want to build the GUI you will also need:

Compiling

With all the dependencies installed, in the project's root folder run the command:

$ task <interface> arch=<architecture>

Where:

  • <interface>: can be cli or gui.
  • <architecture>: can be amd64 or arm64.

For example, if I wanted to build a GUI version of the app, on architecture AMD64, I would run the command:

$ task gui arch=amd64

📝 License

Open Photo AI is released under the AGPL-3.0 License. See LICENSE for details.

👨🏾‍💻 Author

Vinicius Egidio (vinicius.io)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanRegistry

func CleanRegistry()

CleanRegistry releases all resources held by registered models. It iterates through all models in the registry and calls their Destroy method to clean up memory and other resources.

This function should be called when the application is shutting down or when all model instances are no longer needed to prevent resource leaks.

func Destroy

func Destroy()

Destroy cleans up resources used by the model runtime.

This function performs cleanup operations to free memory and resources allocated during initialization. It should be called when the application is shutting down or when the AI functionalities are no longer needed.

It's recommended to use this function with defer for proper cleanup:

Example:

if err := opai.Initialize("myapp", nil); err != nil {
    log.Fatal("Initialization failed:", err)
}
defer opai.Destroy() // Ensure cleanup on exit

func Execute

func Execute[T any](
	ctx context.Context,
	input *types.ImageData,
	ep types.ExecutionProvider,
	onProgress types.InferenceProgress,
	operation types.Operation,
) (T, error)

Execute executes a single image operation and returns the result as a generic data type.

The function selects the appropriate AI model for the operation and runs its inference on the image. The output is not an image, but the information data returned by the model.

Parameters:

  • ctx: A context object that can be used to cancel the operation.
  • input: The input image data to be processed.
  • ep: The execution provider (CPU, CUDA, etc.) to use for inference.
  • onProgress: A callback function called with the progress of the current operation (0-1).
  • operation: The operation to apply to the image.

Returns:

  • T: The result of the operation with the specified generic type
  • error: An error if model selection fails, the operation fails, or the operation type is not supported

Example:

faces, err := Execute[[]types.Face](ctx, inputImage, progressCallback, faceDetectionOp)

func Initialize

func Initialize(name string, onProgress types.DownloadProgress) error

Initialize sets up the model runtime by ensuring all required dependencies are available.

This function performs a two-step initialization process:

  1. Installs the ONNX runtime if not already present in the user's config directory
  2. Initializes the ONNX runtime

The name parameter specifies the application name used to create a dedicated config directory under the user's standard configuration path (e.g., ~/.config/name on Linux). It's important that you reuse the same name on later calls to Initialize() to ensure that the same config directory is used.

Returns an error if any step fails, including:

  • Unable to create config directories or files
  • ONNX runtime initialization failures

Example:

err := opai.Initialize("myapp",  nil)
if err != nil {
    log.Fatal("Failed to initialize:", err)
}
defer opai.Destroy() // Clean up resources

func Process

func Process(
	ctx context.Context,
	input *types.ImageData,
	ep types.ExecutionProvider,
	onProgress types.InferenceProgress,
	operations ...types.Operation,
) (*types.ImageData, error)

Process processes an image through a sequence of image operations.

The function selects the appropriate AI model for each operation and runs its inference on the image. If multiple operations are provided, they are applied in the order specified. The output is the final processed image after all operations are applied.

Parameters:

  • ctx: A context object that can be used to cancel the operation.
  • input: The input image data to be processed.
  • ep: The execution provider (CPU, CUDA, etc.) to use for inference.
  • onProgress: A callback function called with the progress of the current operation (0-1).
  • operations: A variable number of operations to apply sequentially.

Returns:

  • *types.ImageData: The final processed image data after all operations
  • error: An error if model selection fails, any operation fails, or no operations are provided

Example:

output, err := Process(ctx, inputImage, faceRecoveryOp, upscaleOp)

func SuggestEnhancements

func SuggestEnhancements(input *types.ImageData) []types.ModelType

SuggestEnhancements analyzes the input image and returns a list of recommended enhancement.

It evaluates the image for potential face recovery, light adjustment, and upscaling improvements based on image characteristics such as detected faces and resolution.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL