Decentralized Hugging Face - AI models and datasets from IPFS/Filecoin
Project description
DeHug - Decentralized Hugging Face
DeHug is a decentralized platform for AI models and datasets built on IPFS/Filecoin, providing a decentralized alternative to traditional centralized AI model repositories.
Features
- 🌐 Decentralized Storage: Models and datasets stored on IPFS/Filecoin
- 🔒 Censorship Resistant: No single point of failure or control
- 🚀 Easy Integration: Simple Python SDK compatible with existing workflows
- 📊 Data Loading: Support for JSON, CSV, text, and binary formats
- 🔍 Search: Search and discover models and datasets
- 📋 Metadata: Rich metadata support for models and datasets
Installation
pip install dehug
Quick Start
Loading Datasets
from dehug import DeHug
client = DeHug()
# Load a CSV dataset
dataset = client.load_dataset("QmYourDatasetCID", format_hint="csv")
print(dataset.head())
# Load a JSON dataset
data = client.load_dataset("QmYourJSONDataCID", format_hint="json")
print(data)
# Load by name (if registered in DeHug registry)
dataset = client.load_dataset("my-dataset-name", format_hint="csv")
Working with Models
# Load model metadata
model_info = client.load_model("QmYourModelCID")
print(f"Model: {model_info['name']}")
print(f"Task: {model_info['task']}")
print(f"Description: {model_info['description']}")
# Download model files locally
model_path = client.download_model("QmYourModelCID", "./my_models")
print(f"Model downloaded to: {model_path}")
Listing and Searching
# List all available datasets
datasets = client.list_datasets()
for dataset in datasets:
print(f"{dataset['name']}: {dataset['description']}")
# List all available models
models = client.list_models()
for model in models:
print(f"{model['name']}: {model['task']}")
# Search for datasets
results = client.search_datasets("sentiment analysis")
print(f"Found {len(results)} datasets")
# Search for models
results = client.search_models("text classification")
print(f"Found {len(results)} models")
CLI Usage
DeHug includes a command-line interface for easy access:
# Load and display a dataset
dehug dataset QmYourDatasetCID --format csv
# Save dataset to file
dehug dataset QmYourDatasetCID --format csv --output dataset.csv
# Load model metadata
dehug model QmYourModelCID
# Download model files
dehug model QmYourModelCID --download ./models
# List available datasets
dehug list datasets
# List available models
dehug list models
# Search for datasets
dehug search datasets "machine learning"
# Search for models
dehug search models "nlp"
Configuration
You can customize the IPFS gateway and API endpoints by passing a config dictionary:
config = {
'ipfs_gateway': 'https://your-ipfs-gateway.com/ipfs',
'contract_api': 'https://your-api.com',
'request_timeout': 60
}
client = DeHug(config=config)
Default configuration:
- IPFS Gateway:
https://ipfs.io/ipfs - Contract API:
https://api.dehug.io - Request Timeout: 30 seconds
Supported Formats
DeHug automatically detects and handles various data formats:
- JSON: Parsed into Python dictionaries
- CSV: Loaded as pandas DataFrames
- Text: Returned as strings
- Binary: Returned as bytes
You can also specify format hints for better performance:
# Explicitly specify format
csv_data = client.load_dataset("QmDataCID", format_hint="csv")
json_data = client.load_dataset("QmDataCID", format_hint="json")
text_data = client.load_dataset("QmDataCID", format_hint="text")
binary_data = client.load_dataset("QmDataCID", format_hint="binary")
Error Handling
DeHug provides specific exceptions for better error handling:
from dehug import DeHug, DeHugError, NetworkError, DatasetNotFoundError
client = DeHug()
try:
dataset = client.load_dataset("nonexistent-dataset")
except DatasetNotFoundError:
print("Dataset not found")
except NetworkError:
print("Network connection failed")
except DeHugError as e:
print(f"DeHug error: {e}")
API Reference
DeHug Client
load_dataset(name_or_cid, format_hint=None): Load dataset from IPFSload_model(name_or_cid): Load model metadatadownload_model(name_or_cid, download_dir="./models"): Download model fileslist_datasets(): List available datasetslist_models(): List available modelssearch_datasets(query): Search datasets by querysearch_models(query): Search models by query
Utility Functions
load_dataset_from_cid(cid, format_hint=None): Direct dataset loading from CIDload_content_from_cid(cid, format_hint=None): Load any content from CID
Architecture
DeHug consists of two main components:
- Contract API: Metadata registry for models and datasets
- IPFS Storage: Decentralized storage for actual model/data files
The SDK provides a seamless interface to both layers, allowing you to work with decentralized AI assets as easily as with traditional centralized repositories.
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dehug-0.2.1-py3-none-any.whl.
File metadata
- Download URL: dehug-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4659781634eb5dfc097b21b69e7ad28f9ffb0bc2209e2e60ed6979d7ca763df
|
|
| MD5 |
6b12f83c3943b7ec9d09d76897fbccb6
|
|
| BLAKE2b-256 |
654a94d4de905a2eb06f492deb2c00487303b90d5c7f747ec7bb2df9137c6cb6
|