This Streamlit application generates images based on text prompts using the Stable Diffusion model. The app utilizes the Hugging Face diffusers library and can run on both CPU and GPU.
- Load and cache the Stable Diffusion pipeline for efficient reuse
- Generate images from text prompts
- Display generated images within the app
-
Clone the repository:
git clone https://github.com/your-username/stable-diffusion-image-generator.git cd stable-diffusion-image-generator -
Create and activate a virtual environment (optional but recommended):
python -m venv env source env/bin/activate # On Windows, use `env\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up your environment variables by creating a
.envfile and adding your Hugging Face API key:HUGGINGFACE_API_KEY=your_huggingface_api_key_here
-
Run the Streamlit application:
streamlit run app.py
-
Enter a prompt in the text area and click "Generate Image" to create an image.
The main application is contained in app.py and includes:
load_pipeline: Loads the Stable Diffusion pipeline using the Hugging Face API token. The pipeline is cached for reuse across app reruns.generate_image: Generates an image based on the provided text prompt using the Stable Diffusion pipeline.main: Sets up the Streamlit interface, handles user inputs, and displays generated images.
requirements.txt: Lists all the dependencies needed for the project..env: Contains the environment variables, specifically the Hugging Face API key.
Feel free to fork this repository and customize it to suit your needs. Contributions are welcome!