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 sampling-quantizationRun 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 imagedownsample_image(): Adjust the sampling algorithmquantize_image(): Modify quantization behaviormain_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., "sampling-quantization-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/sampling-quantization-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 just sampling (set quantization to 8 bits)
- Progress Gradually: Then introduce quantization concepts
- Compare Methods: Finally explore compression algorithms
Discussion Points
- Sampling: Nyquist theorem, aliasing, pixelation
- Quantization: Posterization, banding, perceptual quality
- Compression: Lossy vs lossless, artifacts, use cases
Assignments
Suggested exercises:
- Find the minimum sampling rate before text becomes unreadable
- Determine the minimum bits per pixel for acceptable quality
- Compare JPEG and PNG for different image types
- Calculate storage requirements for different image sizes