Skip to main content

Run GenAI experiments in a few lines instead of hundreds

Project description

bforbuntyai

Run GenAI experiments in a few lines instead of hundreds.

from bforbuntyai import GAN, dataset
gan = GAN(dataset.FashionMNIST())
gan.train(epochs=50)
gan.generate(n=25)

Installation

# Core (no heavy ML libs)
pip install bforbuntyai

# With PyTorch (GAN, DCGAN, cGAN, VAE, Pix2Pix)
pip install "bforbuntyai[torch]"

# With TensorFlow (AutoEncoder)
pip install "bforbuntyai[tensorflow]"

# With HuggingFace (TextGenerator, TextFineTuner, ImageCaptioner, EthicalEvaluator)
pip install "bforbuntyai[transformers]"

# With Stable Diffusion
pip install "bforbuntyai[diffusers]"

# With ethical evaluation
pip install "bforbuntyai[ethics]"

# Everything at once
pip install "bforbuntyai[all]"

HuggingFace Authentication

Some models (Stable Diffusion gated versions, private datasets) require a HuggingFace token.

from bforbuntyai import auth

auth.login()                    # interactive browser prompt
auth.login(token="hf_...")      # explicit token
auth.whoami()                   # check who is logged in
auth.logout()

# Or pass token directly to any model
sd = StableDiffusion(token="hf_...")
data = dataset.HuggingFace("private/dataset", token="hf_...")

Token is also auto-read from the HF_TOKEN or HUGGINGFACE_HUB_TOKEN environment variable.

Models & Datasets

AutoEncoder (TensorFlow)

from bforbuntyai import AutoEncoder, dataset

ae = AutoEncoder(dataset.MNIST(), encoding_dim=64)
ae.train(epochs=50)
ae.visualize()              # original vs reconstructed grid
ae.save("ae.keras")

GAN — Vanilla (PyTorch)

from bforbuntyai import GAN, dataset

gan = GAN(dataset.FashionMNIST(), latent_dim=100)
gan.train(epochs=50)
gan.generate(n=25)
gan.save("gan.pth")

DCGAN — Convolutional GAN (PyTorch)

from bforbuntyai import DCGAN, dataset

dcgan = DCGAN(dataset.MNIST())
dcgan.train(epochs=20)
dcgan.generate(n=25)

Conditional GAN (PyTorch)

from bforbuntyai import ConditionalGAN, dataset

cgan = ConditionalGAN(dataset.MNIST(), num_classes=10)
cgan.train(epochs=50)
cgan.generate_class(labels=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

VAE — Variational AutoEncoder (PyTorch)

from bforbuntyai import VAE, dataset

vae = VAE(dataset.MNIST(), latent_dim=2)
vae.train(epochs=20)
vae.visualize()              # reconstructions
vae.visualize_latent()       # 2-D scatter plot of latent space
vae.interpolate(img_a, img_b, steps=10)    # morph between images

Pix2Pix Image Translation (PyTorch)

from bforbuntyai import Pix2Pix, dataset

p2p = Pix2Pix(dataset.Edges2Shoes())      # auto-downloads ~1.5 GB
p2p.train(epochs=5)
p2p.visualize()              # input edge | generated photo | real photo

GPT-2 Text Generation

from bforbuntyai import TextGenerator

gen = TextGenerator(model_name="gpt2")
gen.generate("Once upon a time", max_tokens=100, num_return=3)

GPT-2 Fine-tuning

from bforbuntyai import TextFineTuner, dataset

data = dataset.HuggingFace("amazon_polarity", split="train[:200]")
tuner = TextFineTuner(dataset=data)
tuner.train(epochs=3)
tuner.generate("This product is")
tuner.save("./my-gpt2")

Stable Diffusion

from bforbuntyai import StableDiffusion, auth

auth.login()    # required for some model versions
sd = StableDiffusion()
sd.generate("A sunset over mountains, 4K photo", n=4, steps=20)

BLIP Image Captioning

from bforbuntyai import ImageCaptioner

cap = ImageCaptioner()
cap.caption("photo.jpg")
cap.caption("https://example.com/image.jpg")
cap.visualize(["img1.jpg", "img2.jpg", "img3.jpg"])

Ethical Evaluation

from bforbuntyai import EthicalEvaluator

ev = EthicalEvaluator()
ev.evaluate("Some text to check for toxicity and bias")
ev.evaluate_batch(["text one", "text two", "text three"])

Supported Datasets

Dataset Class Used by
MNIST dataset.MNIST() AutoEncoder, GAN, DCGAN, cGAN, VAE
Fashion-MNIST dataset.FashionMNIST() GAN, DCGAN, VAE
CIFAR-10 dataset.CIFAR10() AutoEncoder
HuggingFace dataset.HuggingFace("name", split="...") TextFineTuner
Edges2Shoes dataset.Edges2Shoes() Pix2Pix
Custom folder dataset.Custom("path/", image_size=64) Any image model

Common API

Every model shares the same interface:

Method Description
.train(epochs=...) Train the model, returns self for chaining
.generate(n=...) Generate samples
.visualize() Plot results with matplotlib
.save(path) Save model weights
.load(path) Load model weights

Cache

Downloaded datasets and models are cached at ~/.bforbuntyai/cache/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bforbuntyai-0.2.2.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bforbuntyai-0.2.2-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

Details for the file bforbuntyai-0.2.2.tar.gz.

File metadata

  • Download URL: bforbuntyai-0.2.2.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bforbuntyai-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cbec06dd09004c530ae1ce7cdc699a8d6e16fb7a2a8ba970b5c6b0b08ecda84e
MD5 f4f88e7f593b691cd3026b5f26ad5317
BLAKE2b-256 1e667bb7e1b90abe53f84ac6b5281284074ca4cdd12916ffa88615d35450ee99

See more details on using hashes here.

File details

Details for the file bforbuntyai-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bforbuntyai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 36.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bforbuntyai-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0af22a636c1e2749e5485c34c24c3d25a16b4d4ad393538c1b056903a813d2ee
MD5 7bf07cfc67a189a4be0ed54c66b1b31e
BLAKE2b-256 ef5caec6670a59827cf12ee9de064f3d20900f6a739f60cf8dc120e893d3d571

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page