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
|
|
|
|
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 11 |
short_description: Project demonstrates privacy-preserving techniques for ML
|
| 12 |
---
|
| 13 |
|
| 14 |
+
|
| 15 |
+
# Privacy-Preserving Machine Learning Demo
|
| 16 |
+
|
| 17 |
+
## π Project Overview
|
| 18 |
+
|
| 19 |
+
This project demonstrates privacy-preserving techniques for machine learning on sensitive healthcare data. It implements:
|
| 20 |
+
|
| 21 |
+
- **SHA-256 Hashing** for direct identifiers (SSN)
|
| 22 |
+
- **Pseudonymization** for names
|
| 23 |
+
- **K-Anonymity Generalization** for DOB and income
|
| 24 |
+
- **Laplace Noise** (Differential Privacy) for numerical values
|
| 25 |
+
- **Differentially Private ML Training** using IBM's diffprivlib
|
| 26 |
+
|
| 27 |
+
## π Files Included
|
| 28 |
+
|
| 29 |
+
| File | Description |
|
| 30 |
+
|------|-------------|
|
| 31 |
+
| `app.py` | Gradio web interface (main entry point for HF Spaces) |
|
| 32 |
+
| `privacy_ml_solution.py` | Core ML pipeline with all privacy techniques |
|
| 33 |
+
| `requirements.txt` | Python dependencies |
|
| 34 |
+
| `Assignment2Dataset-1_encrypted.csv` | The encrypted/anonymized dataset |
|
| 35 |
+
| `model_comparison_results.csv` | Performance metrics comparing models |
|
| 36 |
+
| `Privacy_Preserving_ML_Report.docx` | Comprehensive academic report |
|
| 37 |
+
| `Technical_Documentation.docx` | Code and library documentation |
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## π Deploying to Hugging Face Spaces (Step-by-Step for Beginners)
|
| 42 |
+
|
| 43 |
+
### Step 1: Create a Hugging Face Account
|
| 44 |
+
|
| 45 |
+
1. Go to [huggingface.co](https://huggingface.co)
|
| 46 |
+
2. Click "Sign Up" in the top right
|
| 47 |
+
3. Fill in your details and verify your email
|
| 48 |
+
|
| 49 |
+
### Step 2: Create a New Space
|
| 50 |
+
|
| 51 |
+
1. Once logged in, click your profile picture β "New Space"
|
| 52 |
+
2. Fill in the form:
|
| 53 |
+
- **Owner**: Select your username
|
| 54 |
+
- **Space name**: e.g., `privacy-ml-demo`
|
| 55 |
+
- **License**: MIT
|
| 56 |
+
- **SDK**: Select **Gradio**
|
| 57 |
+
- **Hardware**: Keep as "CPU Basic" (free)
|
| 58 |
+
3. Click "Create Space"
|
| 59 |
+
|
| 60 |
+
### Step 3: Upload Your Files
|
| 61 |
+
|
| 62 |
+
**Option A: Using the Web Interface (Easiest)**
|
| 63 |
+
|
| 64 |
+
1. In your new Space, click the "Files" tab
|
| 65 |
+
2. Click "Add file" β "Upload files"
|
| 66 |
+
3. Upload these files:
|
| 67 |
+
- `app.py` (REQUIRED - this is the entry point)
|
| 68 |
+
- `requirements.txt` (REQUIRED)
|
| 69 |
+
- `Assignment2Dataset-1_encrypted.csv` (optional sample data)
|
| 70 |
+
4. Wait for the build to complete (~2-3 minutes)
|
| 71 |
+
|
| 72 |
+
**Option B: Using Git (For More Control)**
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
# Clone your space
|
| 76 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/privacy-ml-demo
|
| 77 |
+
cd privacy-ml-demo
|
| 78 |
+
|
| 79 |
+
# Copy your files into the directory
|
| 80 |
+
cp /path/to/app.py .
|
| 81 |
+
cp /path/to/requirements.txt .
|
| 82 |
+
|
| 83 |
+
# Commit and push
|
| 84 |
+
git add .
|
| 85 |
+
git commit -m "Initial upload"
|
| 86 |
+
git push
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### Step 4: Wait for Build
|
| 90 |
+
|
| 91 |
+
1. Click the "App" tab to see your space building
|
| 92 |
+
2. Watch the logs for any errors
|
| 93 |
+
3. Once complete, your app will be live!
|
| 94 |
+
|
| 95 |
+
### Step 5: Test Your App
|
| 96 |
+
|
| 97 |
+
1. Your app is now live at: `https://huggingface.co/spaces/YOUR_USERNAME/privacy-ml-demo`
|
| 98 |
+
2. Upload a CSV file and adjust the epsilon slider
|
| 99 |
+
3. Click "Run Privacy Analysis" to see results
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
## βοΈ Local Testing (Before Deployment)
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
# Create virtual environment
|
| 107 |
+
python -m venv venv
|
| 108 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 109 |
+
|
| 110 |
+
# Install dependencies
|
| 111 |
+
pip install -r requirements.txt
|
| 112 |
+
|
| 113 |
+
# Run the app
|
| 114 |
+
python app.py
|
| 115 |
+
|
| 116 |
+
# Open http://localhost:7860 in your browser
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
---
|
| 120 |
+
|
| 121 |
+
## π§ Troubleshooting
|
| 122 |
+
|
| 123 |
+
### "Build failed" Error
|
| 124 |
+
- Check that `requirements.txt` has correct package names
|
| 125 |
+
- View build logs for specific error messages
|
| 126 |
+
|
| 127 |
+
### "App crashed" Error
|
| 128 |
+
- Ensure `app.py` has `demo.launch()` at the bottom
|
| 129 |
+
- Check for syntax errors in your code
|
| 130 |
+
|
| 131 |
+
### Slow Loading
|
| 132 |
+
- Free tier spaces "sleep" after inactivity
|
| 133 |
+
- First load takes ~30 seconds to wake up
|
| 134 |
+
|
| 135 |
+
### Memory Issues
|
| 136 |
+
- Reduce `n_estimators` in RandomForest
|
| 137 |
+
- Use smaller test datasets
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## π Understanding the Results
|
| 142 |
+
|
| 143 |
+
| Metric | What it Means |
|
| 144 |
+
|--------|---------------|
|
| 145 |
+
| **Accuracy** | % of correct predictions |
|
| 146 |
+
| **F1 Score** | Balance of precision and recall |
|
| 147 |
+
| **Epsilon (Ξ΅)** | Privacy budget - lower = more privacy |
|
| 148 |
+
|
| 149 |
+
### Privacy Level Guide
|
| 150 |
+
- Ξ΅ = 0.1-0.5: Very high privacy, some accuracy loss
|
| 151 |
+
- Ξ΅ = 1.0: Balanced (recommended)
|
| 152 |
+
- Ξ΅ = 5.0+: Lower privacy, minimal accuracy impact
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## π Learn More
|
| 157 |
+
|
| 158 |
+
- [Differential Privacy Explained](https://desfontain.es/privacy/differential-privacy-awesomeness.html)
|
| 159 |
+
- [IBM diffprivlib Documentation](https://diffprivlib.readthedocs.io/)
|
| 160 |
+
- [Gradio Documentation](https://gradio.app/docs/)
|
| 161 |
+
- [Hugging Face Spaces Guide](https://huggingface.co/docs/hub/spaces)
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## π License
|
| 166 |
+
|
| 167 |
+
MIT License - Feel free to use and modify for your projects.
|
| 168 |
+
|
| 169 |
+
|
| 170 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|