| .devcontainer | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| black_forest_streamlit.py | ||
| black_forest_test.py | ||
| README.md | ||
| requirements.txt | ||
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.clientjsonbase64ostimerequestsstreamlit(for web interface)argparseresqlalchemy(replacessqlite3for ORM)bcrypt(for OTP hashing)streamlit-cookies-manager(for session persistence)python-dateutil(for date handling)secrets(for secure cookie secret generation)
Installation
-
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 -
Install Required Packages
Install the required packages:
pip install -r requirements.txtNote: If
requirements.txtdoesn’t exist yet, manually install the listed packages:pip install requests streamlit sqlalchemy bcrypt streamlit-cookies-manager python-dateutil -
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 Streamlit’s 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
imagesdirectory (local, single-user CLI mode). - Metadata: Stored in
data/image_metadata.dbSQLite database, persistent across deploys.
Database Structure
The database (data/image_metadata.db) includes three tables:
users
- id: Unique identifier (INTEGER PRIMARY KEY)
- email: User’s 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.