A Django-based web application that generates unique digital artwork using a simplified implementation of diffusion models. This project combines deep learning with web development to create an interactive art generation platform.
- AI-Powered Art Generation: Create unique digital artwork using a diffusion model
- Customizable Parameters: Control the generation with prompts and seed values
- Art Gallery: Browse previously generated artworks
- User Authentication: Save and manage your generated artworks (optional)
- Responsive Design: Works on desktop and mobile devices
- Backend: Django (Python web framework)
- AI Model: PyTorch-based diffusion model
- Frontend: HTML5, CSS3, JavaScript
- Database: SQLite (default, can be configured for others)
- Image Processing: PIL/Pillow
- Python 3.8 or higher
- pip (Python package manager)
-
Clone the repository
git clone <repository-url> cd art_generator
-
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up the database
python manage.py migrate
-
Create a superuser (optional)
python manage.py createsuperuser
-
Run the development server
python manage.py runserver
-
Access the application Open your browser and navigate to
http://localhost:8000
-
Generate Artwork:
- Visit the home page
- Optionally provide a text prompt to guide generation
- Optionally specify a seed value for reproducible results
- Click "Generate Art" to create your artwork
-
Browse Gallery:
- Visit the gallery page to see all generated artworks
- View details like seed values, prompts, and creation dates
-
Manage Account (if authenticated):
- Your generated artworks will be associated with your account
- Access additional features if implemented
art_generator/
├── art_project/ # Django project settings
├── art_app/ # Main Django application
│ ├── models.py # Database models
│ ├── views.py # Application logic
│ ├── urls.py # URL routing
│ └── admin.py # Admin interface configuration
├── diffusion_model/ # AI model implementation
│ └── diffusion.py # Diffusion model code
├── templates/ # HTML templates
│ ├── home.html # Main generation interface
│ └── gallery.html # Artwork gallery
├── static/ # Static files (CSS, JS, images)
├── manage.py # Django management script
└── requirements.txt # Python dependencies
- Python 3.8 or higher
- pip (Python package manager)
- Virtual environment tool (venv or virtualenv)
- Minimum 4GB RAM (8GB recommended)
- At least 1GB free disk space
- CPU (GPU optional but not required for this simplified implementation)
Create a requirements.txt
file with the following content:
Django==4.2.7
torch==2.0.1
torchvision==0.15.2
Pillow==10.0.1
numpy==1.24.3
If you have the code in a repository:
git clone <repository-url>
cd art_generator
Or create the directory structure manually:
mkdir art_generator
cd art_generator
On macOS/Linux:
python -m venv venv
source venv/bin/activate
On Windows:
python -m venv venv
venv\Scripts\activate
Create a requirements.txt
file in your project directory with the content above, then run:
pip install -r requirements.txt
Alternatively, install packages individually:
pip install Django==4.2.7
pip install torch==2.0.1 torchvision==0.15.2
pip install Pillow==10.0.1
pip install numpy==1.24.3
If you haven't already created the project structure:
django-admin startproject art_project .
python manage.py startapp art_app
Create the necessary directories:
mkdir -p diffusion_model templates static
Create the following files with the content provided in the previous implementation:
diffusion_model/diffusion.py
- The diffusion model implementationart_app/models.py
- Database modelsart_app/views.py
- Application viewsart_app/urls.py
- URL routing for the apptemplates/home.html
- Main page templatetemplates/gallery.html
- Gallery template
Update the main URLs file art_project/urls.py
to include the app URLs.
Update art_project/settings.py
to include:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'art_app', # Add this line
]
# Add at the bottom of the file
import os
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], # Add this line
'APP_DIRS': True,
# ... other settings
},
]
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
Follow the prompts to create an admin account.
python manage.py runserver
Open your web browser and go to:
- Main application: http://localhost:8000
- Admin interface: http://localhost:8000/admin (if you created a superuser)
Solution: Ensure your virtual environment is activated and Django is installed:
pip install Django==4.2.7
Solution: Install PyTorch with the correct version:
pip install torch==2.0.1 torchvision==0.15.2
Solution: Check your TEMPLATES setting in settings.py and ensure templates directory exists.
Solution: Add CSRF token to your AJAX requests or configure Django settings appropriately.
Solution: This is expected with the CPU implementation. For better performance, consider:
- Using a GPU-enabled PyTorch version
- Reducing image size in the diffusion model settings
- Implementing caching
To verify everything is installed correctly, run:
python manage.py check
This should output: "System check identified no issues (0 silenced)."
For production deployment, you should:
- Set
DEBUG = False
in settings.py - Set up a proper database (PostgreSQL recommended)
- Configure a production web server (e.g., Gunicorn with Nginx)
- Set up static file serving
- Implement proper security measures
Your AI Art Generator should now be ready to use!
You can adjust the diffusion model parameters in diffusion_model/diffusion.py
:
image_size
: Output image dimensions (default: 128x128)timesteps
: Number of diffusion steps (default: 100)- Generation steps in the
generate()
method
Modify the CSS in the HTML templates or add static CSS files to customize the appearance.
By default, the project uses SQLite. To use another database, update the DATABASES
setting in art_project/settings.py
.
- The current implementation uses a CPU-based simplified diffusion model
- For faster generation, consider:
- Using a GPU-accelerated PyTorch installation
- Implementing a more efficient model architecture
- Adding caching mechanisms
- Using background task processing (e.g., Celery)
- The current diffusion model is simplified for demonstration purposes
- Image resolution is limited to 128x128 pixels in the default implementation
- Generation may take several seconds on CPU
- Integration with more advanced models (e.g., Stable Diffusion)
- Higher resolution output
- Style transfer capabilities
- Image editing and manipulation features
- Social features (sharing, commenting, liking)
- Advanced user profiles and collections
-
Dependency conflicts:
- Ensure you're using a virtual environment
- Check Python version compatibility
-
Database errors:
- Run
python manage.py migrate
to apply migrations
- Run
-
Image generation errors:
- Verify all dependencies are installed correctly
- Check available memory
If you encounter issues not covered here, please check:
- Django documentation: https://docs.djangoproject.com/
- PyTorch documentation: https://pytorch.org/docs/
This project is provided for educational purposes. Please check the license terms of any external models or libraries you integrate.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.