Find a file
2025-03-20 22:16:25 -04:00
.devcontainer Added Dev Container Folder 2024-12-17 07:53:04 -05:00
.gitignore MVP 2024-12-17 05:32:40 -05:00
.gitlab-ci.yml Update .gitlab-ci.yml 2025-03-21 00:02:56 +00:00
black_forest_streamlit.py modified: black_forest_streamlit.py 2025-03-20 22:16:25 -04:00
black_forest_test.py MVP 2024-12-17 05:32:40 -05:00
README.md new file: README.md 2025-03-20 21:03:44 -04:00
requirements.txt Update requirements.txt 2025-03-21 00:18:39 +00:00

art.ai.unturf.com

Black Forest Labs Image Generation

This project enables users to generate images based on prompts using the Black Forest Labs API. It now supports multiple users with individual namespaces (albums), secure OTP-based authentication, and enhanced metadata storage. Generated images are stored locally with their metadata in a SQLite database, and a Streamlit web interface provides an interactive experience.

Requirements

  • Python 3.x
  • Required Python packages:
    • http.client
    • json
    • base64
    • os
    • time
    • requests
    • streamlit (for web interface)
    • argparse
    • re
    • sqlalchemy (replaces sqlite3 for ORM)
    • bcrypt (for OTP hashing)
    • streamlit-cookies-manager (for session persistence)
    • python-dateutil (for date handling)
    • secrets (for secure cookie secret generation)

Installation

  1. Clone the Repository

    Clone this repository to your local machine:

    git clone https://git.unturf.com/engineering/unturf/art.ai.unturf.com.git
    cd art.ai.unturf.com
    
  2. Install Required Packages

    Install the required packages:

    pip install -r requirements.txt
    

    Note: If requirements.txt doesnt exist yet, manually install the listed packages:

    pip install requests streamlit sqlalchemy bcrypt streamlit-cookies-manager python-dateutil
    
  3. Set Environment Variables

    Set your Black Forest Labs API key as an environment variable:

    export BLACK_FOREST_LABS_API_KEY="your_api_key_here"
    

    Replace "your_api_key_here" with your actual API key.

    For Streamlit Cloud deployments, optionally set:

    export STREAMLIT_CLOUD="true"
    

    And configure the API key in Streamlits secrets management (see Streamlit Docs).

Usage

Command-Line Interface

Run the script with a prompt (single-user mode, no authentication):

python black_forest_test.py "A beautiful sunset over the mountains"

This creates an images directory for storing generated images.

Web Interface

Run the Streamlit web interface:

streamlit run black_forest_streamlit.py
  • Login: Enter your email to receive a 6-digit OTP, then verify it to access your account.
  • Albums: Create and select namespaces (albums) to organize your images.
  • Generate: Input prompts to generate images within the selected album.
  • View: See images with metadata like seed, model, and generation time.

Output

  • Images: Stored temporarily in memory (deployed) or in an images directory (local, single-user CLI mode).
  • Metadata: Stored in data/image_metadata.db SQLite database, persistent across deploys.

Database Structure

The database (data/image_metadata.db) includes three tables:

users

  • id: Unique identifier (INTEGER PRIMARY KEY)
  • email: Users email (TEXT, UNIQUE)
  • otp_hash: Hashed OTP for authentication (TEXT)
  • otp_expiry: OTP expiration time (DATETIME)

namespaces

  • id: Unique identifier (INTEGER PRIMARY KEY)
  • user_id: Foreign key to users.id (INTEGER)
  • name: Album name (TEXT, UNIQUE per user)

images

  • id: Unique identifier (INTEGER PRIMARY KEY)
  • namespace_id: Foreign key to namespaces.id (INTEGER)
  • slug: Prompt-based slug (TEXT)
  • prompt: Original generation prompt (TEXT)
  • filename: Saved image filename (TEXT)
  • base64_image: Base64 encoded image (TEXT)
  • generation_time: Exact time of generation (DATETIME)
  • seed: Seed used for generation (INTEGER)
  • model_endpoint: Black Forest Labs model used (TEXT, e.g., "flux-dev")

License

This work is dedicated to the public domain.