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.0.tar.gz (29.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.2.0-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bforbuntyai-0.2.0.tar.gz
  • Upload date:
  • Size: 29.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.2.0.tar.gz
Algorithm Hash digest
SHA256 60e346a856bca6d8af9f6b6b226afc248281044bef808d0f52b7df4bcedc1f7c
MD5 2998a876a9959cdda81b4ac21f25f5b5
BLAKE2b-256 b09356a59bfa4d2a9f72b279381ccea33a8a68c692ecc3a5313c6bbfa0b909df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bforbuntyai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceff08042a94d1e6c6c179c253d793f43e646ded8693658c70106342bcc96192
MD5 8c93db511a8c8bec39c4725f7a98329d
BLAKE2b-256 60689b319ea9e2942f8e51e0e4ebf9458c3c6603d64d32e9e64757f40d78cdcc

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