Upload folder using huggingface_hub
Browse files- README.md +10 -2
- c2sentinel.py +41 -0
README.md
CHANGED
|
@@ -45,14 +45,22 @@ C2Sentinel analyzes network connection patterns to identify C2 beacon activity.
|
|
| 45 |
## Installation
|
| 46 |
|
| 47 |
```bash
|
| 48 |
-
pip install torch numpy safetensors
|
| 49 |
```
|
| 50 |
|
| 51 |
---
|
| 52 |
|
| 53 |
## Usage
|
| 54 |
|
| 55 |
-
### Loading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
```python
|
| 58 |
from c2sentinel import C2Sentinel
|
|
|
|
| 45 |
## Installation
|
| 46 |
|
| 47 |
```bash
|
| 48 |
+
pip install torch numpy safetensors huggingface_hub
|
| 49 |
```
|
| 50 |
|
| 51 |
---
|
| 52 |
|
| 53 |
## Usage
|
| 54 |
|
| 55 |
+
### Loading from HuggingFace Hub
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
from c2sentinel import C2Sentinel
|
| 59 |
+
|
| 60 |
+
sentinel = C2Sentinel.from_pretrained('danielostrow/c2sentinel')
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### Loading from Local Files
|
| 64 |
|
| 65 |
```python
|
| 66 |
from c2sentinel import C2Sentinel
|
c2sentinel.py
CHANGED
|
@@ -1753,6 +1753,47 @@ class C2Sentinel:
|
|
| 1753 |
|
| 1754 |
return cls(model, config, device)
|
| 1755 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1756 |
@classmethod
|
| 1757 |
def create_new(cls, device: str = 'auto') -> 'C2Sentinel':
|
| 1758 |
"""Create a new untrained model."""
|
|
|
|
| 1753 |
|
| 1754 |
return cls(model, config, device)
|
| 1755 |
|
| 1756 |
+
@classmethod
|
| 1757 |
+
def from_pretrained(cls, repo_id: str, device: str = 'auto', cache_dir: Optional[str] = None) -> 'C2Sentinel':
|
| 1758 |
+
"""
|
| 1759 |
+
Load model from HuggingFace Hub.
|
| 1760 |
+
|
| 1761 |
+
Args:
|
| 1762 |
+
repo_id: HuggingFace repository ID (e.g., 'danielostrow/c2sentinel')
|
| 1763 |
+
device: Device to load model on ('auto', 'cpu', 'cuda', 'mps')
|
| 1764 |
+
cache_dir: Optional cache directory for downloaded files
|
| 1765 |
+
|
| 1766 |
+
Returns:
|
| 1767 |
+
Loaded C2Sentinel instance
|
| 1768 |
+
"""
|
| 1769 |
+
try:
|
| 1770 |
+
from huggingface_hub import hf_hub_download
|
| 1771 |
+
except ImportError:
|
| 1772 |
+
raise ImportError("huggingface_hub is required for from_pretrained. Install with: pip install huggingface_hub")
|
| 1773 |
+
|
| 1774 |
+
# Download model files
|
| 1775 |
+
model_path = hf_hub_download(
|
| 1776 |
+
repo_id=repo_id,
|
| 1777 |
+
filename="c2_sentinel.safetensors",
|
| 1778 |
+
cache_dir=cache_dir
|
| 1779 |
+
)
|
| 1780 |
+
config_path = hf_hub_download(
|
| 1781 |
+
repo_id=repo_id,
|
| 1782 |
+
filename="c2_sentinel.json",
|
| 1783 |
+
cache_dir=cache_dir
|
| 1784 |
+
)
|
| 1785 |
+
|
| 1786 |
+
# Load config
|
| 1787 |
+
with open(config_path, 'r') as f:
|
| 1788 |
+
config = C2SentinelConfig.from_dict(json.load(f))
|
| 1789 |
+
|
| 1790 |
+
# Load model
|
| 1791 |
+
model = LogBERTC2Sentinel(config)
|
| 1792 |
+
state_dict = load_file(str(model_path))
|
| 1793 |
+
model.load_state_dict(state_dict)
|
| 1794 |
+
|
| 1795 |
+
return cls(model, config, device)
|
| 1796 |
+
|
| 1797 |
@classmethod
|
| 1798 |
def create_new(cls, device: str = 'auto') -> 'C2Sentinel':
|
| 1799 |
"""Create a new untrained model."""
|