Spaces:
Sleeping
Sleeping
File size: 3,125 Bytes
c11fb0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# HuggingFace Space Deployment Guide
This directory contains files for deploying the DGA classifier to HuggingFace Spaces.
## Files
- `app.py` - Main Gradio application
- `requirements.txt` - Python dependencies
- `README.md` - Space description and metadata
## Deployment Steps
### 1. Upload Model to HuggingFace Hub
First, upload your trained model:
```bash
# Make sure you have huggingface_hub installed
pixi add huggingface_hub
# Login to HuggingFace (get token from https://huggingface.co/settings/tokens)
pixi run huggingface-cli login
# Upload the model
cd .. # Go back to project root
pixi run python upload_to_hf.py
```
### 2. Create HuggingFace Space
1. Go to https://huggingface.co/spaces
2. Click "Create new Space"
3. Fill in the details:
- **Space name**: `dga-detector` (or any name you prefer)
- **License**: MIT
- **SDK**: Gradio
- **Hardware**: CPU Basic (free) or GPU if you need faster inference
- **Visibility**: Public
### 3. Upload Files to Space
You can either:
#### Option A: Use Git (Recommended)
```bash
# Clone your Space repository
git clone https://huggingface.co/spaces/ccss17/dga-detector
cd dga-detector
# Copy files from this directory
cp ../hf_space/* .
# Update app.py with your model name
# Edit line 34: MODEL_NAME = "YOUR_USERNAME/dga-transformer-encoder"
# Commit and push
git add .
git commit -m "Initial commit: DGA detector demo"
git push
```
#### Option B: Use Web UI
1. Go to your Space page
2. Click "Files" tab
3. Upload `app.py`, `requirements.txt`, and `README.md`
### 4. Update Model Name
In `app.py`, line 34, change:
```python
MODEL_NAME = "ccss17/dga-transformer-encoder"
```
to:
```python
MODEL_NAME = "YOUR_USERNAME/dga-transformer-encoder"
```
### 5. Wait for Build
HuggingFace will automatically:
- Install dependencies from `requirements.txt`
- Download your model from HuggingFace Hub
- Build and deploy the Gradio app
This usually takes 2-5 minutes.
### 6. Test Your Space
Once deployed, your Space will be available at:
```
https://huggingface.co/spaces/YOUR_USERNAME/dga-detector
```
## Troubleshooting
### Model not found
- Make sure you uploaded the model to HuggingFace Hub first
- Check that the model name in `app.py` matches your repository
### Build fails
- Check the "Logs" tab in your Space
- Ensure `requirements.txt` has all necessary dependencies
- Make sure you're using compatible versions
### Slow inference
- Consider upgrading to GPU hardware (Settings > Hardware)
- Free GPU is available: T4 small
## Customization
### Change theme
In `app.py`, line 179:
```python
with gr.Blocks(title="DGA Domain Classifier", theme=gr.themes.Soft()) as demo:
```
Try other themes: `gr.themes.Base()`, `gr.themes.Default()`, `gr.themes.Glass()`
### Add more examples
Edit the `EXAMPLES` list in `app.py` (line 160)
### Modify UI
Edit the Gradio Blocks structure in `app.py` (lines 179-340)
## Resources
- [HuggingFace Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Gradio Documentation](https://gradio.app/docs/)
- [Model Repository](https://huggingface.co/ccss17/dga-transformer-encoder)
|