Downloads · 30 days
61
10% of all-time downloads
onuion/onuion
onuion is a machine learning model from onuion. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras. The card lists the license as mit.
Downloads · 30 days
61
10% of all-time downloads
All-time downloads
621
Public
Repo size
765 KB
Likes
1
Public
Click a slice to open those files.
.keras375 KB · 43%
From the Hugging Face model README
Real-time Security Risk Analysis Model
Open-source hybrid (rule-based + ML) security risk analysis system for session data analysis with sub-millisecond inference time.
onuion is a production-ready risk analysis system that detects security risks by analyzing session data. Using a hybrid approach (rule-based + ML), it provides both fast detection with deterministic rules and sophisticated pattern recognition with machine learning.
Session Data
↓
[Feature Extractor] → 25 numeric/categorical features
↓
[Rule Engine] → Deterministic risk detection (< 0.1ms)
↓
[TensorFlow Model] → ML-based risk probability (< 0.5ms)
↓
[Risk Aggregator] → Final riskScore + risk array
↓
Risk Analysis Result
Feature Extractor: Converts session data into 25 features
Rule Engine: Fast risk detection with deterministic rules
ip_mismatch: IP changesession_hijacking: Session hijacking indicatorsbot_behavior: Bot behavior patternsgeo_anomaly: Geo-location anomalydevice_fingerprint_mismatch: Device fingerprint mismatchrapid_ip_change: Rapid IP changesuspicious_request_pattern: Suspicious request patternsTensorFlow Model: Feed Forward Neural Network
Risk Aggregator: Combines rule and ML scores
# Clone repository
git clone https://github.com/onuion/onuion.git
cd onuion
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Install in development mode (optional)
pip install -e .
from onuion import analyze_risk
# Session data
session_data = {
"current_ip": "192.168.1.100",
"initial_ip": "192.168.1.50",
"ip_history": ["192.168.1.50", "192.168.1.100"],
"current_geo": {"country": "TR", "city": "Istanbul"},
"initial_geo": {"country": "TR", "city": "Ankara"},
"current_device": {"fingerprint": "fp123"},
"initial_device": {"fingerprint": "fp123"},
"current_browser": {},
"initial_browser": {},
"requests": [
{"timestamp": 1706000000, "method": "GET", "endpoint": "/api/users"}
],
"session_duration_seconds": 10.0,
"current_session_id": "sess_123",
"initial_session_id": "sess_123",
"current_cookies": {},
"initial_cookies": {},
"current_referrer": "",
"initial_referrer": ""
}
# Risk analysis
result = analyze_risk(session_data)
# Results
print(f"Risk Score: {result.riskScore}/100")
print(f"Risks: {result.risk}")
print(f"Inference Time: {result.inference_time_ms:.3f} ms")
{
"riskScore": 45.2, # Risk score (0-100)
"risk": ["ip_mismatch", "geo_anomaly"], # Detected risk types
"rule_score": 40.0, # Rule engine score
"ml_score": 48.0, # ML model score
"confidence": 92.0, # Confidence score
"inference_time_ms": 0.856 # Inference time (ms)
}
See the examples/ directory for more examples:
examples/basic_usage.py: Basic usage exampleexamples/load_from_json.py: Load from JSON fileexamples/sample_session.json: Example session datapython -m onuion.train --synthetic --epochs 50 --output-dir models/onuion_model
# Data format: .npz file
# Contents: X_train, y_train, X_val, y_val (numpy arrays)
python -m onuion.train --data-path data/training_data.npz --epochs 100
onuion supports Hugging Face Hub for model sharing and deployment.
Model Hub: https://huggingface.co/onuion/onuion
Upload a model to Hugging Face Hub:
from onuion.huggingface import upload_to_hub
# Upload a saved model
upload_to_hub(
model_path="models/onuion_model",
repo_id="onuion/onuion",
token="your_hf_token", # Optional, can use huggingface-cli login
private=False
)
Download a model from Hugging Face Hub:
from onuion.huggingface import download_from_hub
from onuion import analyze_risk
# Download model
model = download_from_hub(
repo_id="onuion/onuion",
local_dir="models/downloaded_model"
)
# Use with inference
model.save("models/downloaded_model")
result = analyze_risk(session_data, model_path="models/downloaded_model")
Install Hugging Face dependencies:
pip install huggingface_hub
See examples/huggingface_upload.py and examples/huggingface_download.py for complete examples.
python benchmark/benchmark.py
# Run all tests
pytest tests/
# With coverage
pytest tests/ --cov=onuion --cov-report=html

See the docs/ directory for detailed documentation:
docs/model.md: Model architecture detailsdocs/risk_types.md: Risk type descriptionsdocs/api.md: API referenceWe welcome your contributions! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License. See the LICENSE file for details.
You can open an issue or send a pull request for questions.
Note: This project is prepared for production use, but it is recommended to use a model trained with real data. The default model is only for testing inference purposes.