File size: 3,229 Bytes
05f137b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22610c3
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
---
title: CycleGAN Face-Sketch Converter
emoji: 🎨
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: "1.28.0"
app_file: app.py
pinned: false
---

# 🎨 CycleGAN Face-Sketch Converter

Convert face photos to sketches and vice versa using CycleGAN.

## πŸš€ Deployment on Hugging Face Spaces

### Step 1: Prepare Your Models

After training, run this cell in your notebook:

```python
# Run this in your training notebook
export_for_huggingface(checkpoint_epoch=100)  # Replace 100 with your best epoch
```

This creates two files in `deployment_models/`:
- `photo_to_sketch.pth` (~44 MB)
- `sketch_to_photo.pth` (~44 MB)

### Step 2: Create Hugging Face Space

1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click **"Create new Space"**
3. Configure:
   - **Space name**: `cyclegan-face-sketch`
   - **License**: Choose appropriate license
   - **Select SDK**: **Streamlit**
   - **Space hardware**: CPU Basic (free) or GPU for faster inference

### Step 3: Upload Files

Upload these files to your Space:

```
your-space/
β”œβ”€β”€ app.py                    # Streamlit application
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ photo_to_sketch.pth       # Model file (Photo β†’ Sketch)
β”œβ”€β”€ sketch_to_photo.pth       # Model file (Sketch β†’ Photo)
└── README.md                 # This file (optional)
```

### Step 4: Your Space will Auto-Build

Hugging Face will automatically:
1. Install dependencies from `requirements.txt`
2. Run your Streamlit app
3. Provide a public URL

## πŸ“¦ File Sizes

- `photo_to_sketch.pth`: ~44 MB
- `sketch_to_photo.pth`: ~44 MB
- **Total**: ~88 MB (well within free tier limits)

## 🎯 Features

- βœ… Photo to Sketch conversion
- βœ… Sketch to Photo conversion  
- βœ… Auto-detection of input type
- βœ… Camera input support
- βœ… Download results
- βœ… Responsive UI

## πŸ’‘ Usage Tips

### For Best Results:
- Use clear, front-facing photos
- Ensure good lighting
- Images are automatically resized to 256x256

### Hardware:
- **CPU Basic (Free)**: ~3-5 seconds per image
- **GPU T4 (Paid)**: ~0.5 seconds per image

## πŸ”§ Local Testing

Before deploying, test locally:

```bash
# Install dependencies
pip install -r requirements.txt

# Run Streamlit app
streamlit run app.py
```

Then open http://localhost:8501

## πŸ“Š Model Details

- **Architecture**: CycleGAN with ResNet-based generators
- **Input Size**: 256x256 RGB images
- **Training**: Unpaired face-sketch dataset
- **Loss Functions**: 
  - Adversarial loss (LSGAN)
  - Cycle consistency loss
  - Identity loss

## πŸ› Troubleshooting

### Space doesn't start:
- Check all files are uploaded correctly
- Verify file names match exactly in `app.py`
- Check Space logs for errors

### Out of memory:
- Use CPU Basic hardware
- Models are optimized for CPU inference

### Slow inference:
- Upgrade to GPU hardware in Space settings
- Or use batch processing

## πŸ“ License

[Your License Here]

## πŸ™ Acknowledgments

- CycleGAN paper: [Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks](https://arxiv.org/abs/1703.10593)
- Person Face Sketches dataset: [Kaggle](https://www.kaggle.com/datasets/almightyj/person-face-sketches)