CycleGAN_Streamlit / README.md
cooper0914's picture
Update README.md
05f137b verified

A newer version of the Streamlit SDK is available: 1.57.0

Upgrade
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

  1. Go to Hugging Face 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:

# 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