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.1.tar.gz (29.8 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.1-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bforbuntyai-0.2.1.tar.gz
  • Upload date:
  • Size: 29.8 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.1.tar.gz
Algorithm Hash digest
SHA256 72dbbe1748c97a7163c12e22d471a3212bd7ad1b92dcf8845911eb00262449e8
MD5 7a8d9d0fd7d6869bf87292f572c149b8
BLAKE2b-256 538c3b77529818ee7b7095fd6247cedce5680a7311fea834ffb74da5c253f96c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bforbuntyai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 36.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f61df87482ec97dc7fbaee9891bb8ffaca2fb4b00487ab00871b546490bea799
MD5 607de6c32a5784157d65ab96d1035a0f
BLAKE2b-256 4723a9b4a23c2922eb5c1184799e97e27166c3bbda536eacb8e6d59869f90eb5

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