File size: 5,796 Bytes
4230f20
 
 
 
 
 
 
 
 
 
 
 
 
d7c5b1f
 
373fbd2
d7c5b1f
 
aacf571
 
 
d7c5b1f
 
 
 
 
aacf571
d7c5b1f
aacf571
 
 
d7c5b1f
 
 
 
 
 
aacf571
d7c5b1f
 
 
 
 
 
 
 
 
 
aacf571
 
 
d7c5b1f
aacf571
 
d7c5b1f
aacf571
 
d7c5b1f
 
aacf571
d7c5b1f
 
aacf571
 
 
d7c5b1f
aacf571
 
 
 
d7c5b1f
03f1d2d
aacf571
 
03f1d2d
aacf571
03f1d2d
aacf571
d7c5b1f
 
 
 
 
 
 
 
 
03f1d2d
aacf571
03f1d2d
aacf571
 
 
 
d7c5b1f
af345df
d7c5b1f
aacf571
d7c5b1f
 
 
 
 
aacf571
d7c5b1f
 
 
 
 
 
 
aacf571
 
 
d7c5b1f
 
c600be8
aacf571
 
d7c5b1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c600be8
af345df
d7c5b1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aacf571
 
 
 
d7c5b1f
aacf571
 
 
 
d7c5b1f
 
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
---
title: FaceForgeAI ZeroGPU
emoji: 🐨
colorFrom: pink
colorTo: pink
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
license: mit
short_description: FaceForgeAI_ZeroGPU
---

# 🎨 FaceForge AI
[![Hugging Face Space](https://img.shields.io/badge/πŸ€—%20Open%20in-Hugging%20Face%20Space-yellow)](https://huggingface.co/spaces/VcRlAgent/FaceForgeAI)

**Author:** Vijay S. Chaudhari  
**Runtime:** Gradio + Replicate API πŸš€

---

## 🧠 Overview
**FaceForge AI** transforms your uploaded photo into professional-quality images powered by AI:
- 🎭 **Background Remover** – clean background removal for any image
- πŸ’Ό **Professional Headshots** – studio-quality portraits in multiple styles
- 🌍 **Scene Changer** – place yourself in different environments with identity preservation

This edition uses **Replicate's InstantID** for high-quality identity-preserving transformations with configurable rate limiting for cost control.

---

## ✨ Key Features

βœ… **Three Generation Modes**
- **Background Remover** – removes background using Rembg
- **Professional Headshots** – Studio, Office, Premium Editorial styles
- **Scene Changer** – Coastal Run, Urban Evening, Forest Trail environments

βœ… **User Controls**
- Preset prompt styles via dropdown
- Optional advanced settings (CFG, Steps, Denoise)
- Real-time usage tracking

βœ… **Rate Limiting**
- 5 generations/day (standard mode)
- 10 generations/day (dev mode)
- Midnight UTC reset
- Device-based tracking

---

## 🧩 Tech Stack

| Component | Purpose |
|-----------|---------|
| **Python 3.10+** | Core runtime |
| **Gradio 4.x** | Web UI framework |
| **Replicate API** | InstantID model hosting |
| **InstantID** | Identity-preserving image generation |
| **Rembg 2.x** | Background removal |
| **PyYAML** | Configuration management |
| **Pillow** | Image processing |

---

## 🧰 Installation

### 1️⃣ Clone Repository
```bash
git clone https://github.com/agentofAI/FaceForgeAI.git
cd FaceForgeAI
```

### 2️⃣ Install Dependencies
```bash
pip install -r requirements.txt
```

### 3️⃣ Configure Environment
```bash
cp .env.example .env
# Edit .env and add your REPLICATE_API_TOKEN
```

Get your Replicate API token at: https://replicate.com/account/api-tokens

### 4️⃣ Run Locally
```bash
python app.py
```
Open the local Gradio URL (typically http://127.0.0.1:7860) in your browser.

---

## 🎨 Style Presets

### Professional Headshots

| Style | Description |
|-------|-------------|
| πŸ“Έ **Studio Headshot** | Professional editorial with neutral background, magazine quality |
| 🏒 **Office Setting** | Subtle office background, premium business attire |
| ✨ **Premium Editorial** | High-end minimal studio, composed presence |

### Scene Changer

| Scene | Description |
|-------|-------------|
| πŸ–οΈ **Coastal Run** | Ocean and horizon background, warm sunrise lighting |
| πŸŒƒ **Urban Evening** | City lights, soft ambient night lighting |
| 🌲 **Forest Trail** | Trees and dirt path, diffused outdoor light |

---

## πŸ“ Project Structure

```
faceforge-ai/
β”‚
β”œβ”€β”€ app.py                  # Main Gradio application
β”œβ”€β”€ config.yaml             # Prompts and settings configuration
β”œβ”€β”€ rate_limiter.py         # Rate limiting logic
β”œβ”€β”€ replicate_handler.py    # Replicate API wrapper
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .env.example            # Environment variables template
β”œβ”€β”€ rate_limits.json        # Auto-generated usage tracking
└── README.md               # Documentation
```

---

## βš™οΈ Configuration

### Rate Limits (config.yaml)
```yaml
rate_limit:
  default_daily_limit: 5      # Standard mode
  dev_daily_limit: 10         # Dev mode
  reset_timezone: "UTC"       # Reset at midnight UTC
```

### Dev Mode
Enable higher rate limits in `.env`:
```bash
DEV_MODE=true
```

### Add Custom Styles
Edit `config.yaml` to add new headshot or scene styles:

```yaml
headshots:
  "🎯 Your Style":
    prompt: |
      Your custom prompt here...
      multiple lines supported
    negative: "Things to avoid..."

scenes:
  "πŸŽͺ Your Scene":
    prompt: "Scene description..."
    negative: "Things to avoid..."
```

### Advanced Settings
Toggle "Enable Advanced Settings" in UI to control:
- **CFG Scale**: Prompt adherence (1.0-10.0)
- **Steps**: Generation quality (20-50)
- **Denoise**: Transformation strength (0.5-1.0)

---

## πŸ“Š Rate Limiting

- **Tracking**: Server-side session file per device
- **Reset**: Midnight UTC daily
- **Scope**: Shared across all generation functions
- **Override**: Dev mode doubles the limit

Device fingerprinting uses IP + User-Agent for consistent tracking.

---

## 🧾 Model Credits

| Model | Source / License |
|-------|------------------|
| **InstantID** | [zsxkib/instant-id-basic](https://replicate.com/zsxkib/instant-id-basic) via Replicate |
| **Rembg** | [danielgatis/rembg](https://github.com/danielgatis/rembg) (MIT License) |
| **Gradio** | [gradio-app/gradio](https://github.com/gradio-app/gradio) (Apache 2.0) |

---

## πŸ› Troubleshooting

**"REPLICATE_API_TOKEN not found"**
- Verify `.env` file exists with valid token
- Check token at https://replicate.com/account/api-tokens

**"Daily limit reached"**
- Wait for midnight UTC reset
- Enable `DEV_MODE=true` for higher limits

**Generation fails**
- Verify image uploaded successfully
- Check Replicate API status
- Ensure internet connectivity

**Rate limits not working**
- Delete `rate_limits.json` to reset tracking
- Verify server-side file permissions

---

## πŸ“œ License

This project is for educational and demonstration purposes.  
Each model used retains its original open-source license.

---

Author: Vijay S. Chaudhari
Β© 2025 Vijay S. Chaudhari