# Standalone FM NewGens Generate NewGen images for Football Manager using local Stable Diffusion **🖥️ GUI Available!** - Now includes a user-friendly graphical interface # Intro ![enter image description here](https://raw.githubusercontent.com/karl0ss/comfy_fm24_newgens/refs/heads/main/photo-collage.png) - "There are 10000s of faces out there already" - "There are tools that work the same already?" - "Have you got nothing better to do with your time?" [Example video here](https://www.youtube.com/watch?v=mcGj3_nbV0A) These are some of the questions I think you are going to ask me, but I present to you something I have been working on, **Standalone FM NewGens** # The Idea Taking inspiration from [fm-ai-face-generator](https://github.com/emilmirzayev/fm-ai-face-generator) and [NewGAN-Manager](https://github.com/franl08/NewGAN-Manager), this tool generates unique face images for Football Manager NewGens using local Stable Diffusion instead of requiring a separate ComfyUI server. Thanks to both original projects for the inspiration! So what does this do? Why would you want to use it? (you probably won't but personally, I like a bit more personalization from my NewGens, some I get quite attached to :) ) - This will create images for your NewGens, based off of information provided from the FM database, making a player's image more unique to that player - Generate images locally using Stable Diffusion (no external server required) - Download the images to the specified output directory, all processed players images will be saved as their **uid** from the game - Remove all the background from the generated faces - Create the needed config file for FM to load the faces - You can then rename the generated folder and place it in your **graphics** folder as you would normally and voila! # Install Guide Things you will need that I will not be going over on how to setup. - Python 3.8+ installed - Git installed - At least 4GB of RAM (8GB+ recommended for better performance) - CUDA-compatible GPU (optional, but highly recommended for faster generation) ## Setup Instructions - Use Git to checkout this repo - You need to get a `rtf` file of the players you want to add images for, to do this you need the view and filter supplied with the project - Copy the `filters` and `views` folder over to your `Football Manager 2024` data folder in `Documents`, this may create these folders, or may just add the contained files into your existing folders - You can use `python INSTALL_VIEW_AND_FILTER.py` to do this automatically - Included is the original `is newgen` filter created by the NewGAN-Manager team and a new view created by myself to get the needed data - If you follow [this video](https://youtu.be/pmdIkhfmY6w?t=564) it will show you how to export the `rtf` file, you want to use our view, not the view in the video - Once you have your `rtf` file add it to the root of the current repo - Create a python virtual environment `python -m venv venv` - Activate the venv `.\venv\Scripts\activate` (Windows) or `source venv/bin/activate` (Linux/Mac) - Install the requirements `pip install -r requirements.txt` - Copy the `user_config.cfg.sample` to `user_config.cfg` and make the needed changes - football_manager_version - Version of FM to generate for. Defaults to `2024` - output_dir - Where to save the generated set. Defaults to `./generated_images/` - rtf_file - Path to your exported RTF file with player data - model_name - Hugging Face model to use (see Model Selection section below) - model_dir - Custom directory to store models (optional) ## Usage Options ### **🖥️ GUI Mode (Recommended)** For the best user experience, use the graphical interface: ```bash # Test if GUI works on your system python test_gui.py # Launch the full GUI python run_gui.py ``` ### **🔧 Background Removal Only** If you only need to remove backgrounds from existing images: ```bash # Remove backgrounds from generated images python remove_backgrounds.py ./NewGens/ # Use specific method python remove_backgrounds.py ./NewGens/ --method rembg # Save to different directory python remove_backgrounds.py ./NewGens/ --output-dir ./Processed/ ``` **GUI Features:** - Easy configuration with file browsers - Real-time progress monitoring - Live image preview - Start/stop controls - Comprehensive logging ### **📝 Command Line Mode** For advanced users or automation: ```bash python comfy_fm_newgen.py ``` **Command Line Features:** - Fast batch processing - Resume capability - Detailed logging - Script automation ## Model Selection The tool uses Hugging Face models for image generation. You can specify which model to use in your `user_config.cfg`: ### **Recommended Models for Face Generation:** - `SG161222/Realistic_Vision_V6.0_B1` - **Best choice** for realistic faces (default) - `digiplay/AbsoluteReality` - Photorealistic faces and people - `stabilityai/stable-diffusion-2-1` - General purpose, good for faces - `runwayml/stable-diffusion-v1-5` - Classic SD 1.5, widely supported ### **Model Storage:** - **Default**: Models are stored in Hugging Face cache (`~/.cache/huggingface/`) - **Custom Directory**: Set `model_dir` in config to store models in a specific folder - **Model Size**: Most face models are 2-5GB, ensure you have sufficient disk space - **First Run**: Model downloads automatically when you first run the tool ### **Changing Models:** 1. Edit `model_name` in your `user_config.cfg` 2. Delete the old model from your cache/directory if desired 3. Restart the tool - it will download the new model automatically ## System Requirements - **CPU Mode**: Requires at least 8GB RAM, expect 2-5 minutes per image - **GPU Mode**: Requires CUDA-compatible GPU with at least 4GB VRAM, expect 10-30 seconds per image - First run will download the Stable Diffusion model (~5GB), so ensure you have sufficient disk space ## Features ### **Core Features** - **Local Generation**: No external servers or API keys required - **Model Selection**: Choose from various face generation models via configuration - **Automatic Processing**: Batch process multiple players from your RTF file - **Background Removal**: Automatically removes backgrounds from generated faces - **XML Configuration**: Generates proper Football Manager configuration files - **Resume Support**: Can resume from previous runs without regenerating existing images - **Model Caching**: Downloads and caches models locally for faster subsequent runs ### **🖥️ GUI Features** - **User-Friendly Interface**: Modern tabbed interface with intuitive controls - **File Browsers**: Easy selection of RTF files and output directories - **Real-Time Progress**: Live progress bars and status updates - **Image Preview**: View generated images as they're created - **Configuration Management**: Save and load different configurations - **Error Handling**: Clear error messages and troubleshooting tips - **Multi-threaded**: Non-blocking interface during generation ### **🔧 Background Removal Features** - **Automatic Processing**: Backgrounds removed automatically after generation - **Multiple Methods**: AI-powered (rembg) and simple fallback methods - **Standalone Tool**: `remove_backgrounds.py` for manual processing - **Flexible Options**: Works with or without GPU acceleration - **Batch Processing**: Process entire directories of images ## Background Removal ### **Automatic Background Removal (Built-in)** The application automatically removes backgrounds from generated images during post-processing: **When it works:** - ✅ Images are processed automatically after generation - ✅ Transparent backgrounds for better FM integration - ✅ GPU acceleration when available **When it doesn't work:** - ⚠️ Images keep original backgrounds - ⚠️ May need manual processing ### **Manual Background Removal** If automatic removal fails, use the standalone tool: ```bash # Remove backgrounds from all images in a directory python remove_backgrounds.py ./NewGens/ # Use specific method python remove_backgrounds.py ./NewGens/ --method rembg # Save to different directory python remove_backgrounds.py ./NewGens/ --output-dir ./NewGens_Processed/ ``` ### **Background Removal Methods** | Method | Quality | Speed | Requirements | Notes | |--------|---------|-------|--------------|-------| | **rembg** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | `rembg[gpu]` | Best quality, AI-powered | | **Simple** | ⭐⭐ | ⭐⭐⭐⭐⭐ | Built-in | Fallback method, basic results | ### **Installing Background Removal** **For best quality (recommended):** ```bash pip install rembg[gpu]==2.0.59 ``` **For CPU-only:** ```bash pip install rembg==2.0.59 ``` **If rembg fails:** ```bash # The simple method works without additional dependencies python remove_backgrounds.py ./NewGens/ --method simple ``` ## GUI Troubleshooting ### **Common Issues:** **GUI won't start:** - Ensure Python 3.8+ is installed - Install requirements: `pip install -r requirements.txt` - Check for missing dependencies: `python -c "import tkinter"` **Dependency installation fails:** - Try installing packages individually: `pip install torch torchvision diffusers transformers` - For Python 3.11+, use: `pip install rembg==2.0.59` (instead of 2.0.60) - If `striprtf` fails, try: `pip install striprtf==0.0.28` **Numba/rembg compatibility issues:** - The application now handles missing `rembg` gracefully - Background removal is optional - images will work without it - Test GUI functionality: `python test_gui.py` - If you encounter Numba compilation errors, the GUI will still work **Alternative installation methods:** - **Conda**: `conda install pytorch torchvision torchaudio cpuonly -c pytorch` - **GPU Support**: Replace `cpuonly` with `cudatoolkit=11.8` for CUDA support - **Individual packages**: Install problematic packages one by one to identify issues **Model download fails:** - Check internet connection - Verify disk space (models are 2-5GB) - Try a different model from the recommended list **Images not appearing in preview:** - Check output directory permissions - Ensure images are being generated successfully - Try refreshing the preview tab **Configuration not saving:** - Check file permissions in the project directory - Ensure no other instances are running - Try running as administrator ### **Performance Tips:** - **First run** takes longer due to model download - **Close other applications** during generation for better performance - **Use SSD storage** for faster model loading - **Monitor system resources** - generation is CPU/GPU intensive ## Command Line Usage For advanced users or automation, you can still use the original command-line interface: ```bash python comfy_fm_newgen.py ``` The GUI and command-line versions share the same configuration files and generated data. --- You should get some console output of the progress, good luck! Open an issue here if you're having problems Thanks