| .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 is a Streamlit-based web application that allows users to generate images using the Black Forest Labs API. It supports multiple users with secure OTP-based authentication, collaborative namespaces (albums), and persistent storage of images and metadata in SQLite databases. Users can create albums, generate images with customizable settings, invite collaborators, and download their creations with detailed metadata.
Features
- User Authentication: Secure login via email and one-time password (OTP).
- Namespaces (Albums): Organize images into user-created albums, with support for multiple collaborators.
- Image Generation: Generate images using Black Forest Labs models (e.g.,
flux-dev,flux-pro-1.1) with customizable seeds. - Collaboration: Invite other users to collaborate on albums via email.
- Persistent Storage: Images and metadata are stored in SQLite databases, with per-namespace separation.
- Metadata: Each image includes prompt, seed, model endpoint, and generation timestamp.
- Web Interface: Interactive Streamlit app for login, album management, and image generation/display.
- Downloadable Outputs: Download generated images directly from the interface.
Requirements
checkout requirements.txt
- Python 3.8+
- Required Python packages:
streamlit(web interface)requests(API calls)sqlalchemy(ORM for database management)bcrypt(OTP hashing)streamlit-cookies-manager(session persistence)smtplib(email sending, optional)http.client(BFL API interaction)base64(image encoding)secrets(secure cookie secret generation)- Plus standard libraries:
os,time,json,re,random,socket,tempfile,datetime
Installation
-
Clone the Repository
git clone https://git.unturf.com/engineering/unturf/art.ai.unturf.com.git cd art.ai.unturf.com -
Create Python3 virtualenv & Install Required Packages
Then install:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
Set Environment Variables
Set your Black Forest Labs API key:
export BLACK_FOREST_LABS_API_KEY="your_api_key_here"For Streamlit Cloud deployments, optionally set:
export STREAMLIT_CLOUD="true" export BLACK_FOREST_LABS_API_KEY="your_api_key_here"Alternatively, configure the API key in Streamlit’s secrets management (see Streamlit Docs).
-
SMTP Configuration (Optional)
For OTP and invite emails, configure an SMTP server (e.g.,
localhost:25). If not available, emails are logged to stdout.
Usage
Running the Web Interface
Launch the Streamlit app:
streamlit run black_forest_streamlit.py
- Login: Enter your email to receive a 6-digit OTP (sent via email or logged to console), then verify to log in.
- Album Management: Create new albums or select existing ones from the dropdown.
- Collaboration: Invite collaborators via email from the sidebar and manage access.
- Image Generation: Enter a prompt, choose a model and seed, and generate images within the selected album.
- View & Download: Browse generated images with metadata (prompt, seed, model, timestamp) and download them as JPEGs.
- Logout: End your session from the sidebar.
Output
- Storage: Images and metadata are stored in the
data/directory:main.db: SQLite database for users and namespaces.namespace_<id>.db: Per-namespace SQLite databases for images.cookie_secret.txt: Persistent cookie encryption key.
- Temporary Files: Generated images are stored temporarily in memory during the session for display and download.
Database Structure
Main Database (data/main.db)
-
users:id(INTEGER PRIMARY KEY): Unique user ID.email(STRING, UNIQUE): User’s email.otp_hash(STRING): Hashed OTP for login.otp_expiry(DATETIME): OTP expiration timestamp.
-
namespaces:id(INTEGER PRIMARY KEY): Unique namespace (album) ID.name(STRING): Album name.
-
namespace_users:id(INTEGER PRIMARY KEY): Unique relation ID.user_id(INTEGER, FOREIGN KEY): Referencesusers.id.namespace_id(INTEGER, FOREIGN KEY): Referencesnamespaces.id.- Unique constraint on
(user_id, namespace_id).
Namespace Databases (data/namespace_<id>.db)
images:id(INTEGER PRIMARY KEY): Unique image ID.slug(STRING): Unique slug derived from prompt and timestamp.prompt(STRING): Original prompt text.filename(STRING): Generated filename (e.g.,slug.jpg).base64_image(STRING): Base64-encoded image data.generation_time(DATETIME): Timestamp of generation.seed(INTEGER): Seed used for generation.model_endpoint(STRING): BFL model used (e.g.,flux-dev).
Deployment
For Streamlit Cloud:
- Push the repository to GitHub.
- Connect it to Streamlit Cloud.
- Add
BLACK_FOREST_LABS_API_KEYto Streamlit secrets. - Ensure the
data/directory is writable (Streamlit Cloud uses a temporary filesystem).
Notes
- Local Development: If SMTP isn’t configured, OTPs and invites are logged to the console.
- Security: OTPs expire after 10 minutes; cookies are encrypted using a persistent secret.
- Scalability: Each namespace has its own database to manage large image collections efficiently.
License
This work is dedicated to the public domain.