File size: 11,164 Bytes
b990c11
 
886e630
 
 
 
 
 
713f69a
b990c11
 
cc5958e
886e630
cc5958e
 
 
 
 
 
 
 
 
db4bc77
cc5958e
 
886e630
 
 
cc5958e
886e630
cc5958e
 
 
 
 
 
 
 
 
 
db4bc77
886e630
 
 
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886e630
cc5958e
 
fb609fe
cc5958e
 
 
 
 
 
 
 
 
 
 
 
886e630
 
 
cc5958e
886e630
cc5958e
886e630
cc5958e
886e630
cc5958e
886e630
 
cc5958e
886e630
 
 
cc5958e
 
 
 
 
886e630
 
cc5958e
886e630
 
 
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
713f69a
 
 
cc5958e
886e630
cc5958e
886e630
cc5958e
 
711e100
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886e630
 
 
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886e630
cc5958e
886e630
cc5958e
 
 
 
 
 
886e630
cc5958e
 
 
 
886e630
cc5958e
 
 
 
886e630
 
 
cc5958e
 
 
 
 
 
 
 
 
 
 
 
87c7f72
 
cc5958e
 
 
 
db4bc77
cc5958e
 
 
 
886e630
cc5958e
 
 
87c7f72
886e630
cc5958e
886e630
 
 
cc5958e
 
 
 
 
 
886e630
cc5958e
 
 
 
 
 
 
 
886e630
 
 
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbb9cf7
cc5958e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
---
title: Pepe Meme Generator
emoji: ๐Ÿธ
colorFrom: green
colorTo: blue
sdk: streamlit
sdk_version: 1.31.0
app_file: src/app.py
python_version: "3.11"
---

<div align="center">

# ๐Ÿธ Pepe the Frog AI Meme Generator

### Create custom Pepe memes using AI-powered Stable Diffusion with LoRA fine-tuning

[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Streamlit](https://img.shields.io/badge/Streamlit-1.28+-FF4B4B.svg)](https://streamlit.io)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97-Hugging%20Face-orange)](https://huggingface.co/MJaheen/Pepe_The_Frog_model_v1_lora)

[Demo](https://huggingface.co/spaces/MJaheen/Pepe-Meme-Generator) โ€ข [Documentation](./docs/) โ€ข [Training Guide](./docs/TRAINING.md) โ€ข [Report Bug](https://github.com/MJaheen/-Pepe-Meme-Generator-/issues)

</div>

---

## ๐Ÿ“– Table of Contents

- [Features](#-features)
- [Quick Start](#-quick-start)
- [Installation](#-installation)
- [Usage](#-usage)
- [Model Information](#-model-information)
- [Project Structure](#-project-structure)
- [Training](#-training-your-own-model)
- [Contributing](#-contributing)
- [License](#-license)
- [Acknowledgments](#-acknowledgments)
- [Contact & Support](#-contact--support)

---

## โœจ Features

### ๐ŸŽจ **Multiple AI Models**
- **Pepe Fine-tuned LoRA** - Custom trained on Pepe dataset (1600 steps)
- **Pepe + LCM (FAST)** - 8x faster generation with LCM technology
- **Tiny SD** - Lightweight model for faster CPU generation
- **Small SD** - Balanced speed and quality
- **Base SD 1.5** - Standard Stable Diffusion
- **Dreamlike Photoreal 2.0** - Photorealistic style
- **Openjourney v4** - Artistic Midjourney-inspired style

### โšก **Performance Features**
- **LCM Support**: Generate images in 6 steps (~30 seconds on CPU)
- **GPU Acceleration**: Automatic CUDA detection with xformers support
- **Memory Efficient**: Attention slicing and VAE slicing enabled

### ๐ŸŽญ **Generation Features**
- **Style Presets**: Happy, sad, smug, angry, crying, and more
- **Raw Prompt Mode**: Use exact prompts without automatic enhancements
- **Text Overlays**: Add meme text with Impact font
- **Batch Generation**: Create multiple variations
- **Progress Tracking**: Real-time generation progress bar
- **Seed Control**: Reproducible generations with fixed seeds
- **Gallery System**: View and manage all generated memes

### ๐ŸŽฏ **User Experience**
- **Model Hot-Swapping**: Switch models without restart
- **Interactive UI**: Clean Streamlit interface
- **Example Prompts**: Built-in inspiration gallery
- **Download Support**: Save images with one click
- **Responsive Design**: Works on desktop and mobile

---

## ๐Ÿš€ Quick Start

### Try Online (No Installation)

๐ŸŒ **[Open in Hugging Face Spaces](https://huggingface.co/spaces/MJaheen/Pepe-Meme-Generator)** - Run instantly in your browser!

### Local Installation

```bash
# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/pepe-meme-generator.git
cd pepe-meme-generator

# 2. Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Run the app
streamlit run src/app.py
```

The app will open in your browser at `http://localhost:8501`

---

## ๐Ÿ“ฆ Installation

### System Requirements

- **Python**: 3.10 or higher
- **RAM**: 8GB minimum, 16GB recommended
- **GPU**: Optional (NVIDIA with CUDA for faster generation)
- **Storage**: ~5GB for models and dependencies

### Dependencies

```bash
# Core dependencies
pip install torch torchvision  # PyTorch
pip install diffusers transformers accelerate  # Diffusion models
pip install streamlit  # Web interface
pip install pillow numpy scipy  # Image processing
pip install peft safetensors  # LoRA support
```

Or install everything at once:

```bash
pip install -r requirements.txt
```

### GPU Setup (Optional but Recommended)

For NVIDIA GPUs with CUDA:

```bash
# Install PyTorch with CUDA support
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

# Install xformers for memory-efficient attention
pip install xformers
```

---

## ๐ŸŽฎ Usage

### Basic Usage

1. **Select a Model**: Choose from the dropdown (try "Pepe + LCM (FAST)" for speed)
2. **Enter a Prompt**: e.g., "pepe the frog as a wizard casting spells"
3. **Adjust Settings**: Steps (6 for LCM, 25 for normal), guidance scale, etc.
4. **Generate**: Click "Generate Meme" and wait
5. **Download**: Save your creation!

### Example Prompts

```
pepe_style_frog, wizard casting magical spells, detailed
pepe_style_frog, programmer coding on laptop, cyberpunk style
pepe_style_frog, drinking coffee at sunrise, peaceful
pepe_style_frog, wearing sunglasses, smug expression
pepe_style_frog, crying with rain, emotional, dramatic lighting
```

### Advanced Features

#### **Using LCM for Fast Generation**
1. Select "Pepe + LCM (FAST)" model
2. Use 6 steps (optimal for LCM)
3. Set guidance scale to 1.5
4. Generate in ~30 seconds!

#### **Adding Text Overlays**
1. Expand "Add Text" section
2. Enter top and bottom text
3. Text automatically styled in Impact font
4. Signature "MJ" added to corner

#### **Reproducible Generations**
1. Enable "Fixed Seed" in Advanced Settings
2. Set a seed number (e.g., 42)
3. Same seed + prompt = same image

---

## ๐Ÿค– Model Information

### Fine-Tuned LoRA Model

**Model ID**: `MJaheen/Pepe_The_Frog_model_v1_lora`

**Training Details**:
- **Base Model**: Stable Diffusion v1.5
- **Method**: LoRA (Low-Rank Adaptation)
- **Dataset**: [iresidentevil/pepe_the_frog](https://huggingface.co/datasets/iresidentevil/pepe_the_frog)
- **Training Steps**: 2000
- **Resolution**: 512x512
- **Batch Size**: 1 (4 gradient accumulation)
- **Learning Rate**: 1e-4 (cosine schedule)
- **LoRA Rank**: 16
- **Precision**: Mixed FP16
- **Trigger Word**: `pepe_style_frog`

**Performance**:
- Quality: โญโญโญ (Good)
- Speed (CPU): ~4 minutes (25 steps)
- Speed (GPU): ~15 seconds (25 steps)

---

## ๐Ÿ“ Project Structure

```
pepe-meme-generator/
โ”œโ”€โ”€ src/                          # Source code
โ”‚   โ”œโ”€โ”€ app.py                    # Main Streamlit application
โ”‚   โ”œโ”€โ”€ Fonts/                    # Font files
โ”‚   โ”œโ”€โ”€ model/                    # Model management
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ config.py             # Model configurations
โ”‚   โ”‚   โ””โ”€โ”€ generator.py          # Image generation logic
โ”‚   โ””โ”€โ”€ utils/                    # Utility functions
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ image_processor.py    # Image processing utilities
โ”œโ”€โ”€ docs/                         # Documentation
โ”‚   โ””โ”€โ”€TRAINING.md               # Model training guide
โ”œโ”€โ”€ models/                       # Downloaded models (gitignored)
โ”œโ”€โ”€ outputs/                      # Generated images (gitignored)
โ”œโ”€โ”€ diffusion_model_finetuning.ipynb  # Training notebook
โ”œโ”€โ”€ requirements.txt              # Python dependencies
โ”œโ”€โ”€ .gitignore                    # Git ignore rules
โ”œโ”€โ”€ .dockerignore                 # Docker ignore rules
โ”œโ”€โ”€ Dockerfile                    # Docker configuration
โ”œโ”€โ”€ LICENSE                       # MIT License
โ””โ”€โ”€ README.md                     # This file
```

---

## ๐ŸŽ“ Training Your Own Model

Want to fine-tune your own Pepe model or create a different character?

### Quick Training Overview

```bash
# 1. Prepare your dataset (images + captions)
# 2. Run the training script
accelerator launch train_text_to_image_lora.py \
  --pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5" \
  --train_data_dir="./your-data" \
  --resolution=512 \
  --train_batch_size=1 \
  --gradient_accumulation_steps=4 \
  --max_train_steps=2000 \
  --learning_rate=1e-4 \
  --lr_scheduler="cosine" \
  --output_dir="./output" \
  --rank=16
```

### Complete Training Guide

See **[docs/TRAINING.md] for:
- Dataset preparation
- Training configuration
- Hyperparameter tuning
- Validation and testing
- Model upload to Hugging Face

Or check out the **[diffusion_model_finetuning.ipynb](./diffusion_model_finetuning.ipynb)** notebook!

---

## ๐Ÿ› ๏ธ Technology Stack

### Core Technologies
- **[PyTorch](https://pytorch.org/)** - Deep learning framework
- **[Diffusers](https://github.com/huggingface/diffusers)** - Diffusion models library
- **[Transformers](https://github.com/huggingface/transformers)** - NLP models
- **[PEFT](https://github.com/huggingface/peft)** - Parameter-efficient fine-tuning (LoRA)
- **[Streamlit](https://streamlit.io/)** - Web UI framework

### AI/ML Components
- **Stable Diffusion 1.5** - Base diffusion model
- **LoRA** - Low-Rank Adaptation for efficient fine-tuning
- **LCM** - Latent Consistency Model for fast inference

### Image Processing
- **Pillow (PIL)** - Image manipulation
- **NumPy** - Numerical operations
- **SciPy** - Scientific computing

---

## ๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

### Ways to Contribute
- ๐Ÿ› Report bugs
- ๐Ÿ’ก Suggest new features
- ๐Ÿ“ Improve documentation
- ๐ŸŽจ Add new style presets
- โšก Optimize performance
- ๐Ÿงช Add tests

---

### Development Setup

```bash
# Clone and setup
git clone https://https://github.com/MJaheen/-Pepe-Meme-Generator-
cd pepe-meme-generator
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Make your changes
# Test locally
streamlit run src/app.py
```

# Submit pull request

---

## ๐Ÿ› Troubleshooting

### Common Issues

**Issue**: Out of memory error  
**Solution**: Reduce resolution to 512x512, use CPU mode, or enable memory optimizations

**Issue**: Slow generation on CPU  
**Solution**: Use "Pepe + LCM (FAST)" model with 6 steps

**Issue**: Import errors  
**Solution**: Reinstall dependencies: `pip install -r requirements.txt --force-reinstall`


---

## ๐Ÿ“œ License

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

### Model Licenses
- **Stable Diffusion 1.5**: CreativeML Open RAIL-M License
- **Pepe LoRA**: MIT License
- **Training Dataset**: Check [iresidentevil/pepe_the_frog](https://huggingface.co/datasets/iresidentevil/pepe_the_frog)

---

## ๐Ÿ™ Acknowledgments

### Special Thanks
- **[WorldQuant University](https://www.wqu.edu/ai-lab-computer-vision)** - AI/ML education and resources
- **[Hugging Face](https://huggingface.co/)** - Model hosting and diffusers library
- **[Stability AI](https://stability.ai/)** - Stable Diffusion model
- **[Microsoft](https://github.com/microsoft/LoRA)** - LoRA technique
- **[iresidentevil](https://huggingface.co/iresidentevil)** - Pepe dataset

---

## ๐Ÿ“ž Contact & Support

- **Issues**: [email protected]

---

## ๐ŸŒŸ Star History

If you find this project useful, please consider giving it a โญ star on GitHub!

---

<div align="center">

**Made with โค๏ธ by MJaheen**

*Generate Pepes responsibly! ๐Ÿธ*

</div>