perplexity-cli
🧠 A simple command-line client for the Perplexity API. Ask questions and receive answers directly from the terminal! 🚀🚀🚀
Tiny Dream - An embedded, Header Only, Stable Diffusion C++ implementation
Tiny Dream is a header only, dependency free, partially uncensored, Stable Diffusion implementation written in C++ with primary focus on CPU efficiency, and smaller memory footprint. Tiny Dream runs reasonably fast on the average consumer hardware, require only 1.7 ~ 5.5 GB of RAM to execute, does not enforce Nvidia GPUs presence, and is designed to be embedded on larger codebases (host programs) with an easy to use C++ API. The possibilities are literally endless, or at least extend to the boundaries of Stable Diffusion's latent manifold.
Integrating Tiny Dream on your existing code base is straightforward. Here is what to do without having to do a lot of tedious reading and configuration:
#include "tinydream.hpp"
/*
* Main Entry Point. The only required argument is the Positive Prompt.
* Passing a Negative Prompt (words separated by commas) is highly recommended though.
*
* We recommend that you experiment with different seed & step values
* in order to achieve a desirable result.
*
* ./tinydream "positive prompt" ["negative prompt"] [seed] [step]
*/
int main(int argc, char *argv[])
{
tinyDream td; // stack allocated tinyDream object
// Display the library current inference engine, version number, and copyright notice
std::cout << tinyDream::about() << std::endl;
// At least a positive prompt must be supplied via command line
if (argc < 2) {
std::cout << "Missing Positive (and potentially Negative) Prompt: Describe something you'd like to see generated..." << std::endl;
std::cout << "Example of Prompts:" << std::endl;
// Example of built-in Positive/Negative Prompts
auto prompts = tinyDream::promptExample();
std::cout << "\tPositive Prompt: " << prompts.first << std::endl;
std::cout << "\tNegative Prompt: " << prompts.second << std::endl;
return -1;
}
// Register a log handler callback responsible of
// consuming log messages generated during inference.
td.setLogCallback(logCallback, nullptr);
// Optionally, set the assets path if the pre-trained models
// are not extracted on the same directory as your executable
// The Tiny-Dream assets can be downloaded from: https://pixlab.io/tiny-dream#downloads
td.setAssetsPath("/path/to/tinydream/assets"); // Remove or comment this if your assets are located on the same directory as your executable
// Optionally, set a prefix of your choice to each freshly generated image name
td.setImageOutputPrefix("tinydream-");
// Optionally, set the directory where you want
// the generated images to be stored
td.setImageOutputPath("/home/photos/");
int seedMax = 90;
if (argc > 3) {
/*
* Seed in Stable Diffusion is a number used to initialize the generation.
* Controlling the seed can help you generate reproducible images, experiment
* with other parameters, or prompt variations.
*/
seedMax = std::atoi(argv[3]);
}
int step = 30;
if (argc > 4) {
/*
* adjusting the inference steps in Stable Diffusion: The more steps you use,
* the better quality you'll achieve but you shouldn't set steps as high
* as possible. Around 30 sampling steps (default value) are usually enough
* to achieve high-quality images.
*/
step = std::atoi(argv[4]);
}
/*
* User Supplied Prompts - Generate an image that matches the input criteria.
*
* Positive Prompt (required): Describe something you'd like to see generated (comma separated words).
* Negative Prompt (optional): Describe something you don't like to see generated (comma separated words).
*/
std::string positivePrompt{ argv[1] };
std::string negativePrompt{ "" };
if (argc > 2) {
negativePrompt = std::string{ argv[2] };
}
/*
* Finally, run Stable Diffusion in inference
*
* The supplied log consumer callback registered previously should shortly receive
* all generated log messages (including errors if any) during inference.
*
* Refer to the official documentation at: https://pixlab.io/tiny-dream#tiny-dream-method
* for the expected parameters the tinyDream::dream() method takes.
*/
for (int seed = 1; seed < seedMax; seed++) {
std::string outputImagePath;
td.dream(
positivePrompt,
negativePrompt,
outputImagePath,
true, /* Set to false if you want 512x512 pixels output instead of 2048x2048 output */
seed,
step
);
// You do not need to display the generated image path manually each time via std::cout
// as the supplied log callback should have already done that.
std::cout << "Output Image location: " << outputImagePath << std::endl; // uncomment this if too intrusive
}
return 0;
}
tinyDream with the following exported methods:
git clone https://github.com/symisc/tiny-dream.git
cd tiny-dream
g++ -o tinydream boilerplate.cpp -funsafe-math-optimizations -Ofast -flto=auto -funroll-all-loops -pipe -march=native -std=c++17 -Wall -Wextra `pkg-config --cflags --libs ncnn` -lstdc++ -pthread -Wl -flto -fopt-info-vec-optimized
./tinydream "pyramid, desert, palm trees, river, (landscape), (high quality)"
The Tiny Dream C++ Interface, provides detailed specifications for all of the various methods the Tiny Dream class exports. Once the reader understands the basic principles of operation for Tiny Dream, that document should serve as a reference guide.
As we continue to develop and improve Tiny Dream, we have an exciting roadmap of future addons and enhancements planned. Refer to the Roadmap page at pixlab.io/tiny-dream or the PixLab Blog for the exhaustive list of todos & ongoing progress...
| Pre-Trained Models & Assets Downloads | Getting Started Guide | Licensing | C++ API Reference Guide | Project Roadmap | Features |
|---|
You may find useful the following production-ready projects developed & maintained by PixLab | Symisc Systems:
more like this
🧠 A simple command-line client for the Perplexity API. Ask questions and receive answers directly from the terminal! 🚀🚀🚀
search projects, people, and tags