Spaces:
Sleeping
Sleeping
A newer version of the Streamlit SDK is available: 1.57.0
metadata
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:
# 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
- Go to Hugging Face Spaces
- Click "Create new Space"
- Configure:
- Space name:
cyclegan-face-sketch - License: Choose appropriate license
- Select SDK: Streamlit
- Space hardware: CPU Basic (free) or GPU for faster inference
- Space name:
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:
- Install dependencies from
requirements.txt - Run your Streamlit app
- Provide a public URL
π¦ File Sizes
photo_to_sketch.pth: ~44 MBsketch_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:
# 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
- Person Face Sketches dataset: Kaggle