Spaces:
Runtime error
Runtime error
A newer version of the Streamlit SDK is available: 1.62.0
Quick Start Guide
For Students/Users
Online Usage
Simply visit the Hugging Face Space URL (provided by your instructor) to use the demo directly in your browser. No installation needed!
Local Usage
Clone the repository:
git clone <repository-url> cd edge-detectionRun the setup script:
chmod +x setup.sh ./setup.shStart the demo:
chmod +x run_simple.sh ./run_simple.shOpen your browser to
http://localhost:8501
For Instructors/Developers
Customizing the Demo
The main application is in app.py. Key functions you can modify:
generate_sample_image(): Customize the default sample imageapply_sobel_filter(),apply_prewitt_filter(), etc.: Modify filter implementationsmain_loop(): Change the UI layout and educational content
Using Your Own Images
You have two options:
- Upload at runtime: Users can upload images via the sidebar
- Default image: Modify the
load_sample_image()function to load from a URL or local path
To use images from your own HuggingFace dataset:
image_path = hf_hub_download(
repo_id="your-username/your-dataset",
filename="your-image.jpg",
repo_type="dataset",
)
Deploying to Hugging Face Spaces
Create a Space:
- Go to https://huggingface.co/new-space
- Choose a name (e.g., "edge-detection-demo")
- Select "Streamlit" as the SDK
- Choose "Public" for educational use
Deploy:
chmod +x deploy.sh ./deploy.shEnter your Space name when prompted (e.g., "username/edge-detection-demo")
Troubleshooting
"Import errors" when running locally:
- Make sure you ran
setup.shfirst - Activate the virtual environment:
source venv/bin/activate - Reinstall requirements:
pip install -r requirements.txt
App not loading on HuggingFace:
- Check the "Logs" tab in your Space
- Verify
packages.txtincludes all system dependencies - Ensure Python version in
.python-versionis supported
Images not displaying:
- Check if the HuggingFace dataset is public
- Verify the repo_id and filename in
load_sample_image() - The app will fall back to a generated image if download fails
Educational Tips
For Teaching
- Start Simple: Begin with Roberts Cross to introduce the gradient concept
- Progress Gradually: Move to Sobel/Prewitt, then Laplacian
- Culminate with Canny: Show how optimal edge detection builds on simpler methods
- Use Comparisons: Enable side-by-side comparisons to highlight differences
Discussion Points
- Gradient Operators: Why do we need 2D convolution kernels?
- First vs. Second Order: When is Laplacian better than Sobel?
- Canny's Criteria: What makes an edge detector "optimal"?
- Trade-offs: Speed vs. quality, simplicity vs. robustness
Suggested Exercises
- Compare edge detection on images with different noise levels
- Find optimal Canny thresholds for different types of images
- Analyze how kernel size affects edge localization
- Examine gradient direction patterns in natural images
- Compare computational complexity of different methods