Spaces:
Sleeping
Sleeping
Deployment Guide - Hugging Face Spaces
This guide walks you through deploying the UI Regression Testing System to Hugging Face Spaces.
Prerequisites
- Hugging Face account (https://huggingface.co)
- GitHub account (for repository)
- Git installed locally
Step 1: Create a GitHub Repository
- Go to https://github.com/new
- Create a new repository named
ui-regression-testing - Clone it locally:
git clone https://github.com/YOUR_USERNAME/ui-regression-testing.git cd ui-regression-testing
Step 2: Prepare Your Files
Copy all project files to your repository:
ui-regression-testing/
βββ app.py # Main Gradio app
βββ requirements.txt # Python dependencies
βββ README.md # Documentation
βββ .gitignore # Git ignore file
βββ state_schema.py # Workflow state
βββ report_generator.py # Report generation
βββ screenshot_annotator.py # Screenshot annotation
βββ image_comparison_enhanced.py # Image comparison
βββ workflow.py # LangGraph workflow
βββ agents/
β βββ __init__.py
β βββ agent_0_super_agent.py
β βββ agent_1_design_inspector.py
β βββ agent_2_website_inspector.py
β βββ agent_3_difference_analyzer.py
βββ utils/
βββ __init__.py
βββ figma_client.py
βββ website_capturer.py
Step 3: Create .gitignore
Create a .gitignore file:
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
# IDE
.vscode/
.idea/
*.swp
*.swo
# Environment
.env
.env.local
# Data
data/
reports/
*.png
*.jpg
# OS
.DS_Store
Thumbs.db
Step 4: Update requirements.txt
Ensure your requirements.txt includes:
# Core Dependencies
python-dotenv>=1.0.0
requests>=2.31.0
# LangGraph & LangChain
langgraph>=0.0.50
langchain>=0.1.0
langchain-core>=0.1.0
# Web Automation
playwright>=1.40.0
# Data Processing
numpy>=1.24.3
pandas>=2.1.3
pillow>=11.0.0
# Async Support
aiohttp>=3.9.1
# Utilities
python-dateutil>=2.8.2
scipy>=1.11.0
# Gradio
gradio>=4.0.0
# Hugging Face
huggingface-hub>=0.19.0
transformers>=4.30.0
torch>=2.0.0
# Image processing
opencv-python>=4.8.0
scikit-image>=0.21.0
Step 5: Push to GitHub
git add .
git commit -m "Initial commit: UI Regression Testing System"
git push origin main
Step 6: Create HF Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Fill in:
- Space name:
ui-regression-testing - License:
mit - Space SDK:
Docker(for better control) - Space storage:
Small(minimum) - Visibility:
Public(orPrivate)
- Space name:
- Click "Create Space"
Step 7: Configure Space
Option A: Using Docker (Recommended)
- In your Space settings, select "Docker" as SDK
- Create a
Dockerfilein your repository:
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
wget \
gnupg \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Playwright browsers
RUN pip install --no-cache-dir playwright && \
playwright install
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . .
# Expose port
EXPOSE 7860
# Run the app
CMD ["python", "app.py"]
Option B: Using Gradio SDK (Simpler)
- In your Space settings, select "Gradio" as SDK
- The space will automatically use
app.pyas entry point
Step 8: Connect GitHub Repository
- In Space settings, go to "Repository"
- Connect your GitHub repository
- Enable "Persistent Storage" (optional, for saving results)
Step 9: Configure Environment Variables
In your Space settings, add these secrets:
FIGMA_ACCESS_TOKEN=your_token_here
HUGGINGFACE_TOKEN=your_token_here
Note: Users will provide these through the UI, so these are optional defaults.
Step 10: Deploy
- Push your code to GitHub
- The Space will automatically rebuild
- Monitor the build logs in the Space settings
- Once deployed, your Space will be live at:
https://huggingface.co/spaces/YOUR_USERNAME/ui-regression-testing
Step 11: Test Your Deployment
- Open your Space URL
- Fill in test credentials
- Click "Start Regression Test"
- Verify all features work correctly
Monitoring & Maintenance
View Logs
- Go to Space settings β "Logs"
- Check for errors or warnings
Update Code
- Push changes to GitHub
- Space will automatically rebuild
Monitor Performance
- Track execution time
- Monitor memory usage
- Check error rates
Troubleshooting
Build Fails
- Check Docker build logs
- Verify all dependencies in requirements.txt
- Ensure Python version compatibility
App Crashes
- Check Space logs
- Verify all imports are correct
- Test locally before deploying
Slow Performance
- Optimize image processing
- Cache results
- Consider upgrading Space resources
Memory Issues
- Reduce image resolution
- Implement garbage collection
- Use persistent storage
Optimization Tips
1. Reduce Image Size
# In image_comparison_enhanced.py
img = img.resize((img.width // 2, img.height // 2))
2. Cache Results
from functools import lru_cache
@lru_cache(maxsize=10)
def expensive_operation(key):
# Your code here
pass
3. Use Persistent Storage
import os
storage_dir = "/data" # HF Spaces persistent storage
os.makedirs(storage_dir, exist_ok=True)
Advanced Configuration
Custom Domain
- Go to Space settings β "Custom Domain"
- Add your domain (requires DNS configuration)
Webhooks
- Set up GitHub webhooks for automatic deploys
- Configure in repository settings
Secrets Management
- Use HF Spaces secrets for sensitive data
- Never commit credentials to GitHub
Performance Benchmarks
Expected performance on HF Spaces:
| Task | Time |
|---|---|
| Figma capture | 5-10s |
| Website capture | 10-15s |
| Difference analysis | 5-10s |
| Report generation | 2-5s |
| Total | 30-50s |
Scaling Considerations
For higher traffic:
- Upgrade Space: Use larger instance
- Add Caching: Cache comparison results
- Optimize Images: Reduce resolution
- Async Processing: Use background jobs
- Load Balancing: Use multiple instances
Support & Resources
Next Steps
- Deploy to HF Spaces
- Share with team
- Gather feedback
- Iterate and improve
- Monitor performance
- Scale as needed
Happy deploying! π