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.1.0.tar.gz (25.7 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.1.0-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bforbuntyai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6074ab97fb1720c2d6b02a83b5b1ad170c45d01990f9eb3f6e5c476e89ff5095
MD5 b985f3b754712b0266bc018fbbcfe5d6
BLAKE2b-256 fad93277b2056f1f372947029ad09a90cc72091750e3679472b3938ad5417962

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bforbuntyai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae68dfc06c90bf07cc7b7a27ab871b8b3a8341e1e64f8046f1357be1be889edc
MD5 2f2cb7ba36f7c88b78525d27fb5cf44d
BLAKE2b-256 40c0b5e8912fcedd74718282ac7107a6ef01fcf92788dcdc8e3f42c3d16c8892

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