File size: 6,941 Bytes
6a30001
38d21c4
6a30001
 
 
 
 
 
38d21c4
6a30001
 
 
 
d9ab1b1
6a30001
8b657a5
6a30001
8b657a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
---
title: OpenWB
emoji: πŸš€
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
- streamlit
pinned: false
short_description: Streamlit template space
---

# πŸ€— OpenWB - Free W&B Alternative

A free, open-source experiment tracking platform hosted on HuggingFace Spaces. Track your ML experiments with beautiful dashboards, all powered by HuggingFace infrastructure.

## ✨ Features

- πŸ” **HuggingFace Authentication** - Connect with your HF token
- πŸ“Š **Interactive Dashboards** - Beautiful charts powered by Plotly
- πŸš€ **Easy API** - Simple Python client for logging metrics
- πŸ’Ύ **Free Storage** - Uses HuggingFace Hub for data persistence
- πŸ”„ **Real-time Updates** - Live dashboard updates
- πŸ“ˆ **Multiple Chart Types** - Line plots, scatter plots, histograms
- 🎯 **Experiment Comparison** - Compare multiple runs
- πŸ“‹ **Configuration Tracking** - Store and view experiment configs

## πŸš€ Quick Start

### 1. Deploy on HuggingFace Spaces

1. Go to [HuggingFace Spaces](https://huggingface.co/new-space)
2. Choose **Docker** as SDK
3. Select **Streamlit** template
4. Copy all the files from this repository
5. Deploy your space

### 2. Get Your API Key

1. Visit your deployed space
2. Connect with your HuggingFace token
3. Copy your generated API key from the dashboard

### 3. Install Client Library

```bash
pip install requests
```

### 4. Start Tracking

```python
from client import MLTracker

# Initialize tracker
tracker = MLTracker(
    api_key="your-api-key-here",
    base_url="https://your-space-name.hf.space"
)

# Start experiment
tracker.init("my_first_experiment", config={
    "model": "ResNet50",
    "dataset": "CIFAR-10",
    "learning_rate": 0.001,
    "batch_size": 32
})

# Log metrics during training
for epoch in range(100):
    # Your training code here
    loss = train_one_epoch()
    accuracy = evaluate_model()
    
    # Log to ML Tracker
    tracker.log({
        "loss": loss,
        "accuracy": accuracy,
        "epoch": epoch
    })

# Finish experiment
tracker.finish()
```

## πŸ“ Project Structure

```
ml-tracker/
β”œβ”€β”€ Dockerfile              # HuggingFace Spaces Docker config
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ app.py                  # Main Streamlit dashboard
β”œβ”€β”€ api.py                  # FastAPI backend (optional)
β”œβ”€β”€ client.py               # Python client library
└── README.md               # This file
```

## πŸ”§ Configuration

### Environment Variables

You can set these environment variables for easier usage:

```bash
export ML_TRACKER_API_KEY="your-api-key"
export ML_TRACKER_BASE_URL="https://your-space-name.hf.space"
```

### HuggingFace Space Settings

In your Space settings, you can:
- Enable/disable public access
- Set custom domain
- Configure hardware (upgrade for better performance)

## πŸ’‘ Usage Examples

### Basic Usage

```python
import mltracker

# Initialize with environment variables
mltracker.init("experiment_name", config={
    "model": "BERT",
    "dataset": "IMDB"
})

# Log metrics
mltracker.log({"loss": 0.5, "accuracy": 0.85})
mltracker.log({"loss": 0.3, "accuracy": 0.90})

# Finish
mltracker.finish()
```

### Advanced Usage

```python
from client import MLTracker

tracker = MLTracker(api_key="...", base_url="...")

# Multiple experiments
for lr in [0.001, 0.01, 0.1]:
    tracker.init(f"lr_{lr}", config={"learning_rate": lr})
    
    for epoch in range(10):
        # Training code
        loss = train_with_lr(lr)
        tracker.log({"loss": loss})
    
    tracker.finish()

# Get experiment data
experiments = tracker.get_experiments()
for exp in experiments:
    print(f"Experiment: {exp['experiment']}")
    print(f"Steps: {exp['total_steps']}")
```

### PyTorch Integration

```python
import torch
import torch.nn as nn
from client import MLTracker

# Initialize tracker
tracker = MLTracker(api_key="...", base_url="...")
tracker.init("pytorch_experiment", config={
    "model": "ResNet18",
    "optimizer": "Adam",
    "learning_rate": 0.001
})

# Training loop
model = resnet18()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
criterion = nn.CrossEntropyLoss()

for epoch in range(100):
    for batch_idx, (data, target) in enumerate(train_loader):
        # Forward pass
        output = model(data)
        loss = criterion(output, target)
        
        # Backward pass
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        
        # Log metrics
        if batch_idx % 100 == 0:
            tracker.log({
                "loss": loss.item(),
                "epoch": epoch,
                "batch": batch_idx
            })
    
    # Validation
    val_accuracy = evaluate(model, val_loader)
    tracker.log({"val_accuracy": val_accuracy})
```

## 🎨 Dashboard Features

### Metrics Visualization
- **Line Charts** - Track metrics over time
- **Multi-metric Plots** - Compare different metrics
- **Real-time Updates** - Live dashboard refresh

### Experiment Management
- **Experiment List** - View all your experiments
- **Configuration Viewer** - See experiment settings
- **Data Export** - Download raw data

### Comparison Tools
- **Multi-experiment View** - Compare different runs
- **Metric Filtering** - Focus on specific metrics
- **Time Range Selection** - Zoom into specific periods

## πŸ”’ Security

- **Token-based Auth** - Secure HuggingFace token authentication
- **API Key Management** - Unique API keys per user
- **Data Isolation** - Each user's data is separate
- **HTTPS Only** - All communication encrypted

## πŸ› οΈ Development

### Local Development

```bash
# Clone repository
git clone https://github.com/yourusername/ml-tracker
cd ml-tracker

# Install dependencies
pip install -r requirements.txt

# Run locally
streamlit run app.py
```

### Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

## πŸ“š API Reference

### MLTracker Class

```python
class MLTracker:
    def __init__(self, api_key: str, base_url: str)
    def init(self, experiment_name: str, config: dict = None)
    def log(self, metrics: dict, step: int = None)
    def get_experiments(self) -> list
    def get_experiment(self, name: str) -> dict
    def delete_experiment(self, name: str)
    def finish(self)
```

### Global Functions

```python
def init(experiment_name: str, config: dict = None, api_key: str = None, base_url: str = None)
def log(metrics: dict, step: int = None)
def finish()
```

## 🀝 Support

- **Issues** - Report bugs on GitHub
- **Discussions** - Ask questions in GitHub Discussions
- **Documentation** - Check the wiki for detailed guides

## πŸ“„ License

MIT License - See LICENSE file for details

## πŸ™ Acknowledgments

- HuggingFace for providing free hosting
- Plotly for beautiful charts
- Streamlit for easy web apps
- The ML community for inspiration

---

**Happy Experimenting!** πŸ§ͺ✨