Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.13.0
Hugging Face Spaces Deployment Guide
Quick Start - Deploy to Hugging Face Spaces
Option 1: Web Upload (Easiest)
Create a New Space
- Go to https://huggingface.co/new-space
- Name your space (e.g., "stable-diffusion-style-explorer")
- Select Gradio as the SDK
- Choose your preferred visibility (Public/Private)
- Click "Create Space"
Upload Files
- Click "Files" tab in your new Space
- Click "Add file" → "Upload files"
- Upload these files from
hf_app/folder:app.pyrequirements.txtREADME.md
- Click "Commit changes to main"
Wait for Build
- The Space will automatically build (takes 5-10 minutes first time)
- You'll see build logs in the "Logs" tab
- Once complete, your app will be live!
Option 2: Git Push (Advanced)
# Navigate to the hf_app directory
cd C:\Users\sidhe\TSAIV4\Session15-Assignment\hf_app
# Initialize git (if not already done)
git init
# Add Hugging Face Space as remote
# Replace YOUR_USERNAME and YOUR_SPACE_NAME
git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
# Add and commit files
git add .
git commit -m "Initial commit: Stable Diffusion Style Explorer"
# Push to Hugging Face
git push origin main
Local Testing (Optional)
Test the app locally before deploying:
# Navigate to hf_app directory
cd C:\Users\sidhe\TSAIV4\Session15-Assignment\hf_app
# Install dependencies
pip install -r requirements.txt
# Run the app
python app.py
The app will open at http://localhost:7860
Hardware Requirements
For Hugging Face Spaces:
- Free Tier (CPU): Works but slow (~2-3 minutes per image)
- Upgraded (GPU): Recommended for production
- T4 GPU: ~10-15 seconds per image
- A10G GPU: ~5-8 seconds per image
To Upgrade Space Hardware:
- Go to your Space settings
- Click "Hardware" tab
- Select GPU tier (requires payment)
Troubleshooting
Build Fails
- Check
requirements.txtversions are compatible - Review build logs in Spaces "Logs" tab
- Ensure all imports in
app.pyare inrequirements.txt
Out of Memory
- Reduce
num_inference_stepsdefault value - Use CPU instead of GPU (slower but more memory)
- Upgrade to larger GPU tier
Slow Generation
- Upgrade to GPU hardware
- Reduce inference steps (trade quality for speed)
- Consider caching the pipeline
Customization
Add More Styles
Edit app.py and add to the STYLES dictionary:
STYLES = {
# ... existing styles ...
"Your Style Name": {
"repo": "sd-concepts-library/your-concept",
"token": "<your-token>",
"description": "Your style description"
}
}
Change Base Model
Replace in app.py:
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", # or another model
torch_dtype=dtype,
safety_checker=None
).to(device)
Adjust Default Parameters
Modify the default values in the Gradio components:
steps_single = gr.Slider(..., value=30, ...)- Change default stepsguidance_single = gr.Slider(..., value=7.5, ...)- Change guidance scale
Next Steps
- ✅ Deploy to Hugging Face Spaces
- ✅ Test with different prompts and styles
- ✅ Share your Space URL with others
- ✅ Monitor usage in Space analytics
- ✅ Iterate based on user feedback
Support
- Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
- Gradio Documentation: https://gradio.app/docs
- Diffusers Documentation: https://huggingface.co/docs/diffusers